问题描述
- gridview中datarowbound只对第一行有效
-
我想在点击编辑按钮后根据编辑模板中 lbSingInTime是否有值 来判断 cbSignIn是否该选中,在点击第一行的编辑按钮时能根据lbsingintime是否有值判断是否选中cbsignin,但从第二开始,lbsignintime明明有值,cbsignin却处于未选中状态'>/asp:Label
protected void grv1_RowDataBound(object sender, GridViewRowEventArgs e)
{if (e.Row.RowState == DataControlRowState.Edit) { CheckBox cbSignIn = (CheckBox)e.Row.FindControl("cbSignIn"); Label lbSignIn = (Label)e.Row.FindControl("lbSingInTime"); if (lbSignIn.Text.ToString().Trim() != "") { cbSignIn.Checked = true; cbSignIn.Enabled = false; } else { cbSignIn.Checked = false; cbSignIn.Enabled = true; } }
解决方案
protected void OnRowCreate(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == (DataControlRowState.Alternate | DataControlRowState.Normal)
|| e.Row.RowState == DataControlRowState.Normal)
{
CheckBox cbSignIn = (CheckBox)e.Row.FindControl("cbSignIn");
Label lbSignIn = (Label)e.Row.FindControl("lbSingInTime");
if (lbSignIn.Text.ToString().Trim() != "")
{
cbSignIn.Checked = true;
cbSignIn.Enabled = false;
}
else
{
cbSignIn.Checked = false;
cbSignIn.Enabled = true;
}
}
}
}
时间: 2025-01-31 10:45:45