3

I have a product list user control in my application (gridview). I have nearly the same logic for end user & admin pages (List of products).

The role 'end user' can only view a product & an admin can 'edit' and 'delete' a product.

I plan to use a user control for products and some how dynamically add buttons based on user role. Is this possible with webforms or should I drop this idea altogether ?

Zo Has
  • 12,599
  • 22
  • 87
  • 149

1 Answers1

2

You can show / hide the button on server side RowDataBound event depending upon your condition. The hidden controls html is not generated and sent on client.

void gridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {

      if(DataBinder.Eval(e.Row.DataItem, "ColumnName").ToString() == "SomeValue")
           e.Row.FindControl("YourControlID").Visible = false; 
  }
}
Adil
  • 146,340
  • 25
  • 209
  • 204