简体   繁体   English

只允许某些用户编辑ASPxGridView

[英]Only Allow Certain Users to Edit ASPxGridView

I've got an ASPxGridView that I would like to allow some users to have read and others users write access to. 我有一个ASPxGridView,我希望允许某些用户具有读取权限,而另一些用户具有写入权限。 Ideally this would be based on Active Directory groups. 理想情况下,这将基于Active Directory组。
How can I do this? 我怎样才能做到这一点?

If you're using in-place editing of rows, then it would be a matter of hiding the controls that would allow a user to edit the grid. 如果您使用的是行的就地编辑,那么将是隐藏允许用户编辑网格的控件的问题。

You can do this by hooking into the GridView's RowDataBound event with an event handler, and checking the user's role. 您可以通过使用事件处理程序连接到GridView的RowDataBound事件并检查用户的角色来完成此操作。 If they fail the check, hide the editing controls. 如果他们未通过检查,则隐藏编辑控件。

void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  {
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      if (!Roles.IsUserInRole("Admin"))
      {
        // Hide the edit controls.
        // This would be your "Edit" button or something.
        e.Row.Cells[1].Controls[0].Visible = false;  
      }
    }
  }

I've ended up creating an event handler for the DataBound event and disabling the Command Column as follows: 我最终为DataBound事件创建了一个事件处理程序,并如下所示禁用了Command Column:

protected void ASPxGridView1_DataBound(object sender, EventArgs e)
{ 
  if (!User.IsInRole(ConfigurationSettings.AppSettings["EditActiveDirectoryGroup"]))
  {
    foreach (GridViewColumn c in ASPxGridView1.Columns)
    {
      if (c.GetType() == typeof(GridViewCommandColumn))
      {
        c.Visible = false;
      }
    }
  }
}

If you want to enable the EditButton conditionally only for certain rows, there is an example CQ66919 over at DevExpress.com. 如果只想对某些行有条件地启用EditButton ,则在DevExpress.com上有一个示例CQ66919

In addition they refer to example E366 for newer versions of the ASPxGridView . 此外,它们还参考示例E366来获取ASPxGridView较新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM