仅允许某些用户编辑 ASPxGridView

发布于 2024-08-04 11:09:42 字数 96 浏览 5 评论 0原文

我有一个 ASPxGridView,我希望允许某些用户对其进行读取,而其他用户对其进行写入访问。理想情况下,这将基于 Active Directory 组。
我该怎么做?

I've got an ASPxGridView that I would like to allow some users to have read and others users write access to. Ideally this would be based on Active Directory groups.
How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡淡绿茶香 2024-08-11 11:09:42

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

您可以通过使用事件处理程序挂钩 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;  
      }
    }
  }

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. 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;  
      }
    }
  }
旧时模样 2024-08-11 11:09:42

我最终为 DataBound 事件创建了一个事件处理程序并禁用了命令列,如下所示:

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

I've ended up creating an event handler for the DataBound event and disabling the Command Column as follows:

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;
      }
    }
  }
}
小姐丶请自重 2024-08-11 11:09:42

如果您想仅对某些行有条件地启用 EditButton,可以使用示例 CQ66919 位于 DevExpress.com。

此外,他们还参考了示例E366以获得较新版本的ASPxGridView

If you want to enable the EditButton conditionally only for certain rows, there is an example CQ66919 over at DevExpress.com.

In addition they refer to example E366 for newer versions of the ASPxGridView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文