Displaying Edit button in GridView based on Role

后端 未结 2 1073
感动是毒
感动是毒 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: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;
    }
    

提交回复
热议问题