RadGrid make column readonly in batch edit

5 posts, 1 answers
  1. Richard
    Richard avatar
    3 posts
    Member since:
    Sep 2016

    Posted 28 Mar Link to this post

    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

  2. Eyup
    Admin
    Eyup avatar
    3825 posts

    Posted 02 Apr Link to this post

    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.
  3. Richard
    Richard avatar
    3 posts
    Member since:
    Sep 2016

    Posted 02 Apr in reply to Eyup Link to this post

    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?

  4. Answer
    Eyup
    Admin
    Eyup avatar
    3825 posts

    Posted 05 Apr Link to this post

    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.
  5. Richard
    Richard avatar
    3 posts
    Member since:
    Sep 2016

    Posted 05 Apr in reply to Eyup Link to this post

    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.

Back to Top