Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a column called "sign Off" and if the column value is "Yes" then the grid view row should not editable.

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;
       }

   }
Posted
Updated 18-Oct-17 0:33am

1 solution

use RowDataBound[^] Event

for label control you will have to use the Text property to read the text value
I suspect the command buttons are not labels, it should be a button or linkbutton control. please check that and change the casting control
void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow) {
               GridViewRow row = (GridViewRow)e.Row;
               Label myTextBox = row.FindControl("lbl_SignOff") as Label;
               if (myTextBox.Text == "Yes")
               {
                   LinkButton btnUpdate = row.FindControl("btn_Update") as LinkButton;
                   LinkButton btnCancel = row.FindControl("btn_Cancel") as LinkButton;

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


       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900