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 rend
Anyway take into account this more correct code:
foreach (CommandField column in grdMovies.Columns.OfType<CommandField>)
{
column.Visible = false;
}
Use ButtonField
with CommandName = Edit
.
You can hide the column in Page_Load
function based on the user's role:
const int _editColumnIndex = 0;
void Page_Load(object sender, EventArgs e)
{
if(!User.IsInRole("Manager"))
grdMovies.Columns[_editColumnIndex].Visible = false;
}