views:

1146

answers:

3

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?

+1  A: 

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;  
      }
    }
  }
womp
Is there a RowDataBoundEvent? See http://www.devexpress.com/Support/Center/p/Q133547.aspx.
macleojw
eee.. sorry I thought that was a typo. I didn't realize there was a third party component called "ASPxGrid". Well, an alternative would be to go through all the rows after the grid has finished being databound, instead of on a row-by-row basis.
womp
ASPxGridView is a gridview component which is part of the DevExpress Visual Studio plugin.
macleojw
A: 

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;
      }
    }
  }
}
macleojw
A: 

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.

Uwe Keim