Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top