我有一个带有CheckBox列的网格,如下所示:
{{3}}
我想简单地启用所选行的CheckBox" e"在更新/取消后编辑和禁用。这就是我的尝试:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((CheckBox)e.Row.FindControl("chkStatus")).Enabled = false;
}
}
catch
{
}
}
这是为了在更新/编辑时启用CheckBox:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvRow = GridView1.Rows[index];
if (e.CommandName == "Edit" || e.CommandName == "Update")
{
((CheckBox)gvRow.FindControl("chkStatus")).Enabled = true;
}
else if (e.CommandName == "Cancel")
{
}
}
但问题是每次编辑/更新后,RowDataBound再次触发并禁用CheckBox。
我该如何避免这种情况?