根据条件启用/禁用网格行编辑 [英] Enabling/disabling grid row editing based on condition

查看:92
本文介绍了根据条件启用/禁用网格行编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview中有一个列,如果值为Yes,则gridview不可编辑,否则用户可以编辑。



我尝试了两种不同的方法行命令和行数据绑定。



我尝试过:



I have a column in gridview and if the value is "Yes" then the gridview should not editable else user can edit.

I tried 2 different methods in row command and row data bound.

What I have tried:

protected void grdChangeRequirement_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
        Label myTextBox = row.FindControl("lbl_SignOff") as Label;

        if (myTextBox.ToString() == "Yes")
        {
            Label btnUpdate = row.FindControl("btn_Update") as Label;
            Label btnCancel = row.FindControl("btn_Cancel") as Label;

            btnUpdate.Visible = false;
            btnCancel.Visible = false;
        }

    }







protected void grdChangeRequirement_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           Label btnUpdate = (e.Row.FindControl("btn_Update") as Label);
           Label btnCancel = (e.Row.FindControl("btn_Cancel") as Label);
           if (e.Row.Cells[12].Text == "Yes")
           {
               btnUpdate.Enabled = false;
           }
       }

   }

推荐答案

我想,你需要RowDataBound事件og网格。

I think, you need the "RowDataBound event" og grid.
protected void grdChangeRequirement_RowDataBound(object sender, GridViewRowEventArgs e)  
{ 
    //Code to get the textbox value [To Do]
    //Check the valeu 
    if (myTextBox.ToString() == "Yes")
    {
    // Code to disable the edit..
    }
}


尝试

try
protected void grdChangeRequirement_RowDataBound(object sender, GridViewRowEventArgs e)
       {

           if (e.Row.RowType == DataControlRowType.DataRow) {
               GridViewRow row = e.Row;
               Label lbl_SignOff = row.FindControl("lbl_SignOff") as Label;
               Label btnUpdate = row.FindControl("btn_Update") as Label;
               Label btnCancel = row.FindControl("btn_Cancel") as Label;
               if (lbl_SignOff.Text == "Yes")
               {
                   btnUpdate.Visible = false;
                   btnCancel.Visible = false;
               }
           }
       }


这篇关于根据条件启用/禁用网格行编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆