I have a Gridview with ItemTemplate using some Labels and 3 Button (Deactivate, Delete and Edit) as seen in picture below:
I want to hide these buttons from some users base on their username (Label UserName on Gridview), for example:
If UserName == "some string"
then hide the Deactivate, Delete and Edit buttonsHow do I do this in code behind RowDataBound
event?
Yes by using Gridview RowDataBound event you can do that
protected void grd1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl=e.Row.FindControl("your cotrol Id")as Label;
if(lbl!=null && lbl.Text.Trim()=="some string")
{
e.Row.FindControl("deactivate btn Id").Visible = false;
e.Row.FindControl("delete btn Id").Visible = false;
e.Row.FindControl("edit btn Id").Visible = false;
}
}
}