Aspx:
<asp:GridView ID="GridView1" DataKeyNames="id" runat="server" AutoGenerateColumns="false" onrowcommand="GridView1_RowCommand"> <Columns> <asp:BoundField DataField="ID" HeaderText="ID" /> <asp:TemplateField HeaderText="title"> <ItemTemplate> <asp:Label ID="LabText" runat="server" Text='<%#Eval("Title") %>'></asp:Label> <asp:LinkButton ID="lbTest" runat="server" CommandName="test" CommandArgument='<%# ((GridViewRow)Container).RowIndex %>'>点击</asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
codeBehide:GridView1_RowCommand
int index= Convert.ToInt32(e.CommandArgument.ToString()); Response.Write(((Label)this.GridView1.Rows[index].FindControl("LabText")).Text);
if (e.CommandName.Equals("test"))
{
GridViewRow gview = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
int RowIndex = gview.RowIndex;
}
还在用GridView? 你应该还是个学生吧?哈哈 出来你就知道错了哦