I am using a RadGrid in batch edit mode with 4 editable columns.
This is working fine but I need to optionally set the columns as non-editable depending on which user is editing the screen.
eg. user A can edit all columns but user B can only edit 2 and user C only 1 column.
Is there a way to make an editable column non-editable when drawing the grid.
Thanks
Richard
4 Answers, 1 is accepted
You can achieve this requirement using the ReadOnly property of the columns. Access the columns during the DataBinding or PreRender event handler of the grid and depending on the logged User, you can change their ReadOnly property to true:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/Common/using-the--getitems-getcolumn-and-getcolumnsafe-methods#columns
I hope this will prove helpful.
Regards,
Eyup
Progress Telerik
I tried the following:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
GridTableView masterTable = (sender as RadGrid).MasterTableView;
GridColumn productNameColumn = masterTable.GetColumnSafe("ProductName") as GridColumn;
}
But 'productNameColumn' does not have a readonly property, am I missing something?
Yes, this approach is correct. However, you need to use a GridBoundColumn:
GridBoundColumn productNameColumn = masterTable.GetColumnSafe(
"ProductName"
)
as
GridBoundColumn;
if
(productNameColumn !=
null
)
{
productNameColumn.ReadOnly=
true
;
}
This if condition will also return true for column types inheriting GridBoundColumn like GridNumericTextBox. You can find a table with this information here:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/columns/column-types#specific-properties-and-generated-controls
Regards,
Eyup
Progress Telerik
Hi
Thank you - this worked (altho I had to use a GridTemplateColumn):
GridTemplateColumn productNameColumn = masterTable.GetColumnSafe("ProductName") as GridTemplateColumn;
This does break the 'onBatchEditCommand' as the item is removed from the 'oldValues/newValues' lists,
however I should be able to work round this with some extra code to pull the original values.
Thank you for your help
Richard.