我有一个gridview定义为
<asp:GridView ID="gv1" runat="server" AutoPostBack="true" onselectedindexchanged="gv1_SelectedIndexChanged">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chk1" runat="server" />
<asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" ReadOnly="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代码被处理为
protected void gv1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach(GridViewRow row in gv1.Rows)
{
CheckBox check1 = (CheckBox)row.FindControl("chk1");
if(check1 != null && check1.Checked)
{
label1.Text = row.Cells[1].Text;
}
}
}
所需的列位于索引 1
但是,未获得该值。