gridview 行中取控件出现错误:未将对象引用设置到对象的实例.
for (int i = 0; i < this.dgv_Userinfo.Rows.Count; i++)
{
decimal id = Convert.ToInt32(this.dgv_Userinfo.DataKeys[i].Value);
if((this.dgv_Userinfo.Rows[i].Cells[0].FindControl("CheckBox1")as CheckBox).Checked == true)
{
OAEntities oa = new OAEntities();
Table_UserInfo user = new Table_UserInfo();
user.U_ID = id;
oa.Table_UserInfo.Attach(user);
oa.Entry(user).State = System.Data.EntityState.Deleted;
oa.SaveChanges();
}
}
我就是想把gridview复选框中选中的行删除,网上找到的这种方法,然后运行这句: if((this.dgv_Userinfo.Rows[i].Cells[0].FindControl("CheckBox1")as CheckBox).Checked == true)
出现错误,显示未将对象引用设置到对象的实例.
是什么原因呢?求助,谢谢