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