RKh
RKh

Reputation: 14159

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: 7891

Answers (2)

Raghuveer
Raghuveer

Reputation: 2637

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: 176956

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