GridView中Checkbox操作数据库的问题
我在我的GridView中添加了一个模板列,其中添加了一个checkbox,为了实现分页的功能我在数据库中添加了一个bit类型的字段ischecked判断是否被选中,当选中了checkbox的时候就修改数据库中的该字段为1,否则为0,这些都实现了,可是问题也出现了,我在checkbox的checkedchanged事件中添加了如下代码
protected void ckbID_CheckedChanged(object sender, EventArgs e)
{ //gvCorporationInfo为我的GridView
for (int rowindex = 0; rowindex < gvCorporationInfo.Rows.Count; rowindex++)
{
if (((CheckBox)gvCorporationInfo.Rows[rowindex].Cells[1].FindControl("ckbID")).Checked)
{
int id = Convert.ToInt32(gvCorporationInfo.DataKeys[rowindex].Value);
string strsql = "update CorporationInfo set ischecked = 1 where corpID = " + id;
//ExecuteBrg.executeOtherTabBrg(string strsql)方法为操作数据库的方法,做的就是ExcuteNonQuery();
if (ExecuteBrg.executeOtherTabBrg(strsql))
{
//bindGV();为绑定GridView的方法,实现了对数据库相应数据的查询与显示
bindGV();
}
}
else
{
int id = Convert.ToInt32(gvCorporationInfo.DataKeys[rowindex].Value);
string strsql = "update CorporationInfo set ischecked = 0 where corpID = " + id;
if (ExecuteBrg.executeOtherTabBrg(strsql))
{
bindGV();
}
}
}
}
在运行的时候我选择第一行的checkBox可以实现修改数据库中的ischecked字段为1或0,可是第二行开始就不可以了,怎样点都不会做出修改,更不用说绑定了,打断点的时候发现“rowindex”始终是0,要怎样做才可以实现在我无论修改哪行的checkbox的checked的时候都会做出相应的修改和绑定呢?谢谢大家了