This is a migrated thread and some comments may be shown as answers.

RadGrid make column readonly in batch edit

4 Answers 1317 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 28 Mar 2019, 11:11 AM

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

Sort by
0
Eyup
Telerik team
answered on 02 Apr 2019, 09:29 AM
Hello Richard,

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Richard
Top achievements
Rank 1
answered on 02 Apr 2019, 10:48 AM

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?

0
Accepted
Eyup
Telerik team
answered on 05 Apr 2019, 09:14 AM
Hello Richard,

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Richard
Top achievements
Rank 1
answered on 05 Apr 2019, 10:03 AM

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.

Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Richard
Top achievements
Rank 1
Share this question
or