我有以下 GridView -
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="checkButton_OnClick" AutoPostBack="true"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="tID" DataField="tID"
SortExpression="tID" HeaderStyle-CssClass = "hideGridColumn" ItemStyle-CssClass="hideGridColumn"></asp:BoundField>
<asp:BoundField HeaderText="Name" HeaderStyle-HorizontalAlign=Center DataField="NAME"
SortExpression="NAME" ItemStyle-HorizontalAlign=Center></asp:BoundField>
</Columns>
然后找到检查复选框的行 -
foreach (GridViewRow gvr in table_example.Rows)
{
if (((CheckBox)gvr.FindControl("CheckBox1")).Checked == true)
{
//Here I need the tID of the row that is checked
WebService1 ws = new WebService1();
ws.addID(tID);
}
}
我需要获取tID
选中行的,我试过 -
int tID = gvr.cells["tID"];
然而这并没有奏效。