I have a Grid View. I added AutoGenerateEditButton=True
.
I want to display that button to users that belong to a certain role. If not the button is not rendered.
What do you recommend? Which event do I have to handle to accomplish that purpose?
Do I have to work with template-driven control such as ListView?
Solution:
<Columns>
<asp:CommandField
ShowEditButton="True" />
<asp:BoundField
DataField="Id"
ReadOnly="true"
Visible="true" />
<asp:BoundField
DataField="Title"
HeaderText="Title" />
</Columns>
And the GridView's Load event:
if(!User.IsInRole("Manager"))
{
for (int i = 0; i < grdMovies.Columns.Count; i++)
{
if (grdMovies.Columns[i] is CommandField)
{
grdMovies.Columns[i].Visible = false;
}
}
}