在GridView中,新增一列->"模版列",然后编辑模版,把CheckBox拖进去就行.
代码如下:
<
asp:TemplateField HeaderText
=
"
投票
"
>
< ItemTemplate >
< asp:CheckBox ID = " CheckBox " runat = " server " />
</ ItemTemplate >
</ asp:TemplateField >
< ItemTemplate >
< asp:CheckBox ID = " CheckBox " runat = " server " />
</ ItemTemplate >
</ asp:TemplateField >
检查CheckBox的状态代码
foreach
(GridViewRow row
in
GV_VoteList.Rows)
{
CheckBox ckb = (CheckBox)row.FindControl( " CheckBox " );
if (ckb.Checked)
{
vote.UpdateVote(Int32.Parse(GV_VoteList.DataKeys[row.RowIndex].Values[ " VoteID " ].ToString()));
Lb_VoteMessage.Visible = true ;
}
}
{
CheckBox ckb = (CheckBox)row.FindControl( " CheckBox " );
if (ckb.Checked)
{
vote.UpdateVote(Int32.Parse(GV_VoteList.DataKeys[row.RowIndex].Values[ " VoteID " ].ToString()));
Lb_VoteMessage.Visible = true ;
}
}
注意:我这里有个隐藏的VoteID列,因此可以这样检查.