Hide Image button from some rows in Gridview
I have added an image button in the template field of the gridview. The gridview contains 20 rows. In all the rows, the image button is being added. Now, if i wish to hide the开发者_如何学运维 image button from some rows, what should i do?
I cannot remove from the gridview else that would go away from all rows.
Please guide
Let me know for any query.
Thanks!
Make use of RowDataBound
Event avaialbe with the GridView where you can hide the control you want for the given row.
void grv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(condition)
{
ImageButton imgBtn= (ImageButton)e.Row.FindControl("mybuttonid");
imgBtn.Visible = false;
}
}
}
In RowDataBound Event:
if (e.Row.RowType == DataControlRowType.DataRow)
{
((ImageButton)e.Row.FindControl("imgbtnImage")).Visible = false;
}
精彩评论