RKh
RKh

Reputation: 14161

How to disable a cell of a GridView row?

I have a GridView control whose first two columns have buttons. When the row is being created, I want to check if the sixth column text is "Locked" or not. If yes then the button in the first cell should not be visible.

The first two columns of the GridView looks like this:

enter image description here

Upvotes: 1

Views: 7889

Answers (2)

Raghuveer
Raghuveer

Reputation: 2638

create a CSS class

.invisible
{ 
   display:none;
}


protected void GridView1_DataBound(object sender, GridViewRowEventArgs e)
 {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.Cells[5].Text=="Locked")
        {
              e.Row.Cells[0].CssClass = "invisible"
        }
     }
   }

Upvotes: 3

Pranay Rana
Pranay Rana

Reputation: 176896

You need to do something as below to hinde the button control form the cell...

protected void GridView1_DataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[5].Text=="Locked")
            {
                (e.Row.FindControl("idofButton1") as Button).Visible=false;
            }
        }
    }

Upvotes: 2

Related Questions