Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 仅允许某些用户编辑ASPxGridView_C#_Security_Devexpress_Aspxgridview - Fatal编程技术网

C# 仅允许某些用户编辑ASPxGridView

C# 仅允许某些用户编辑ASPxGridView,c#,security,devexpress,aspxgridview,C#,Security,Devexpress,Aspxgridview,我有一个ASPxGridView,我希望允许一些用户具有读取权限,其他用户具有写入权限。理想情况下,这将基于Active Directory组。 如何执行此操作?如果使用行的就地编辑,则需要隐藏允许用户编辑网格的控件 可以通过使用事件处理程序挂接GridView的RowDataBound事件并检查用户的角色来实现这一点。如果检查失败,则隐藏编辑控件 void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)

我有一个ASPxGridView,我希望允许一些用户具有读取权限,其他用户具有写入权限。理想情况下,这将基于Active Directory组。

如何执行此操作?

如果使用行的就地编辑,则需要隐藏允许用户编辑网格的控件

可以通过使用事件处理程序挂接GridView的RowDataBound事件并检查用户的角色来实现这一点。如果检查失败,则隐藏编辑控件

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;  
      }
    }
  }

最后,我为数据绑定事件创建了一个事件处理程序,并禁用了命令列,如下所示:

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;
      }
    }
  }
}

如果您只想有条件地为某些行启用
编辑按钮
,DevExpress.com上有一个示例


此外,对于较新版本的
ASPxGridView

是否存在RowDataBoundEvent,请参考示例?看,eee。。对不起,我以为那是个打字错误。我不知道有一个叫做“ASPxGrid”的第三方组件。另一种方法是在网格完成数据绑定后遍历所有行,而不是逐行。ASPxGridView是一个gridview组件,它是DevExpress Visual Studio插件的一部分。