GridView中CheckBox、CheckBoxField取值的方法

前台代码:

<Columns>
<asp:TemplateField HeaderText="选择">
<HeaderStyle HorizontalAlign="Center" Height="25px" Width="45px" />
<ItemTemplate>
<asp:CheckBox ID="ckb" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="sid" HeaderText="编号" />
<asp:BoundField DataField="cname" HeaderText="姓名" />
</Columns>

后台代码:

foreach (GridViewRow gvr in this.GridView1.Rows) 

{ 

     Control ctl = gvr.FindControl("ckb"); 

     CheckBox ck = (CheckBox)ctl; 

     if (ck.Checked) 

     { 

         TableCellCollection cell = gvr.Cells; 

         string wid += cell[1].Text+","; 

     } 

} 

你可能感兴趣的:(checkbox)