您的位置:首页 > 其它

GridView中CheckBox、CheckBoxField取值的方法

2012-11-30 21:09 363 查看
前台代码:

<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+",";
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: