Displaying Edit button in GridView based on Role

后端 未结 2 1067
感动是毒
感动是毒 2021-01-29 04:12

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

相关标签:
2条回答
  • 2021-01-29 04:28

    Anyway take into account this more correct code:

    foreach (CommandField column in grdMovies.Columns.OfType<CommandField>)
    {
        column.Visible = false;
    }
    
    0 讨论(0)
  • 2021-01-29 04:36

    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;
    }
    
    0 讨论(0)
提交回复
热议问题