I am trying to remove the editing interfaces when a user is not allowed to edit the RadGrid contents. The grid has a master table view with 2 detail tables at the same level. In the grid's PreRender event, I use the following code to hide the edit and delete columns, but only the Master View's columns are hidden when the page is first rendered. Clicking the master grid's Refresh Data button then hides the detail tables' columns even if this code is prevented from re-running, so it seems the setting has been made, but not used during the first render. I have similar code in the ItemCreated event which sets the GridCommandItem display to None. That also displays correctly for the master table on the initial page render, but only takes affect for the detail tables after the Refresh Data. How can I hide the columns and command items during the first page rendering. I am using Telerik version 2010.1.415.35.
protected void RadGridSubjectArea_PreRender(object sender, EventArgs e) |
{ |
Trace.Write("Event", this.ToString() + ": " + "RadGridSubjectArea_PreRender"); |
RadGrid grid = (RadGrid)sender; |
bool editAllowed = this.isEditAllowed; |
grid.AllowAutomaticInserts = editAllowed; //Added safety since controls should be hidden |
grid.AllowAutomaticDeletes = editAllowed; |
grid.AllowAutomaticUpdates = editAllowed; |
GridTableView view = grid.MasterTableView; //Top-level view |
//Set editability of this view and child views at any level |
this.GridTableHierarchySetEditability(view, editAllowed); |
//Try to force the display to refresh? //Clicking master grid's Refresh Data hides the columns even if this code is NOT re-run, // so it seems the setting has been made, but not used during the first render? |
//grid.Rebind(); //This prevents clicking Refresh Data from working. |
} |
protected void GridTableHierarchySetEditability(GridTableView view, bool editAllowed) |
{ |
Trace.Write("Event", this.ToString() + ": " + "GridTableHierarchySetEditability"); |
//Recursively set editability for this table view and all its children. |
//Unnecessary since we hide command buttons, but this is further protection. |
view.AllowAutomaticInserts = editAllowed; |
view.AllowAutomaticDeletes = editAllowed; |
view.AllowAutomaticUpdates = editAllowed; |
//Show or hide command columns (generally edit or delete) |
foreach (GridColumn col in view.Columns) |
{ |
if (col.ColumnType == "GridEditCommandColumn" || col.ColumnType == "GridButtonColumn") |
{ |
col.Visible = editAllowed; |
} |
} |
//Process any child tables |
foreach (GridTableView child in view.DetailTables) |
{ |
this.GridTableHierarchySetEditability(child, editAllowed); |
} |
} |
<BR> |