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+","; 
     } 
} 
posted @ 2012-11-30 21:09  Mark1997  阅读(1827)  评论(0编辑  收藏  举报