2 ohmybbq ohmybbq 于 2014.12.05 23:03 提问

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;

            }


    }

1个回答

q107770540
q107770540   Ds   Rxr 2014.12.06 12:01
 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;

            }

            }         
        }
    }
Csdn user default icon
上传中...
上传图片
插入图片