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?
views:
1146answers:
3
+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
2009-09-09 15:55:34
Is there a RowDataBoundEvent? See http://www.devexpress.com/Support/Center/p/Q133547.aspx.
macleojw
2009-09-09 16:24:36
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
2009-09-09 16:39:12
ASPxGridView is a gridview component which is part of the DevExpress Visual Studio plugin.
macleojw
2009-09-10 08:17:39
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
2009-09-14 09:19:01