我想根据使用asp.net c#
在网格视图中选中的复选框更新数据库列值在下面的编码中,chbox显示空引用异常
foreach (GridViewRow rows in grdApproval.Rows)
{
if (Chbox.Checked)
{
int RoleID = Convert.ToInt32(ViewState["RoleID"].ToString());
int TsId = Convert.ToInt32(hfTimesheetId.Value);
var Qry = (from m1 in TSEntity.Roles
where m1.RoleId == RoleID
select m1).FirstOrDefault();
if (Qry != null)
{
var QryEditTimesheet = (from m2 in TSEntity.TimeSheets
where m2.Id == TsId
select m2).FirstOrDefault();
if (QryEditTimesheet != null)
{
QryEditTimesheet.IsApproved = true;
QryEditTimesheet.ApprovedBy = ViewState["EmpName"].ToString();
QryEditTimesheet.ModifiedDate = DateTime.Now;
TSEntity.SaveChanges();
}
}
BindGrid();
}
else
{
BindGrid();
}
}
答案 0 :(得分:0)
没有任何进一步的信息,我可以猜测。
首先我建议将第一行更改为
foreach(GridViewRow row in grdApproval.Rows)
第二个可以尝试将第二行更改为
if(row.Columns["yourcheckboxcolumnnumber"].checked)
希望有所帮助。