Reputation: 14161
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:
Upvotes: 1
Views: 7889
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
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