Changing columns to readonly

4 posts, 0 answers
  1. Mike
    Mike avatar
    10 posts
    Member since:
    Jan 2014

    Posted 01 Jul 2015 Link to this post

    I have a page which contains a batch mode grid (created declaratively in the aspx file) and all of the code to support the grid.  This grid page is contained within an IFrame in various pages on the site.  Depending upon which page is hosting the IFrame, we want to override the behavior of the grid so that the columns are read-only.  The default behavior allows the columns to be edited, but when the grid is included within certain pages, we want all of the columns to be read-only. 

    Using (column as GridBoundColumn).ReadOnly = true; during the server-side PreRender event can fail if the column type is GridTemplateColumn (with Object reference not set).  That said,  I know I can respond to the BatchEditOpening event and use args.set_cancel(true) to prevent users from editing cells, but was hoping for a simple server-side solution to change the column to read-only. 

    For the moment, I am responding to the PreRender event and testing for ColumnType before setting the column to read-only.  That just happens to work for me since the only GridTemplateColumn column is declaratively set to ReadOnly and all of the other column types seem to work.  However, that seems error prone.  Is there a way to easily set every column to read-only in my c# code?


  2. Angel Petrov
    Angel Petrov avatar
    1152 posts

    Posted 06 Jul 2015 Link to this post


    Generally you should be able to set the GridTemplateColumn as ReadOnly on the server by subscribing to the PreRender event. Can you please send us the markup and code-behind of the page so we could examine it and research what might be causing this behavior.

    Additionally bear in mind that I tried reproducing the problem in an isolated sample but was not able to do so. Please examine the attached web site and tell us what differs in your case. If you can modify it so that the problem can be replicated that would be great.

    Angel Petrov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Mike
    Mike avatar
    10 posts
    Member since:
    Jan 2014

    Posted 10 Aug 2015 in reply to Angel Petrov Link to this post

    Hi Angel,

    As a follow up, is there a way to change a column's readonly status with client-side javascript?   In this case, the user selects from two choices in a dropdown list.  Based upon the selection, I need to modify the content of ​a field (I update the innerText).  I can update the innerText, but if I click on the field, I get an error saying "Object doesn't support property or method 'getElementsByTagName'".  Looking at the call stack, it appears to fail while attempting to invoke _openEditFromEvent.  I suspect this is because the field is editable.  Perhaps, if I set the column to read-only, the edit event would not be generated. I want to do this on the client since the user must be able to seamlessly switch their selection to restore the original value and allow editing of the column. 

    If I execute the following code, it replaces the innerText as expected.  However, if I select any of the updated fields I get the error. If I don't change the innerText, I can click on the cells without getting the error (but the value is not correct).

    // ... get the 'editable' Local Currency price cells and ...
    var regAvgPriceLCCell = dataItem.get_cell("REG_PRICE_LC");
    var dirAvgPriceLCCell = dataItem.get_cell("DIR_PRICE_LC");
    var yoiAvgPriceLCCell = dataItem.get_cell("YOI_AVG_PRICE_LC");
    var y1AvgPriceLCCell = dataItem.get_cell("Y1_AVG_PRICE_LC");

    //... and if we are asked to display dollar values ...
    if (document.getElementById("<%=hiddenUseLocalCurrency.ClientID%>").value == "false") {
        regAvgPriceLCCell.innerText = dataItem.get_cell("REG_PRICE_DOLLARS").innerText.replace("$", "");
        dirAvgPriceLCCell.innerText = dataItem.get_cell("DIR_PRICE_DOLLARS").innerText.replace("$", "");
        yoiAvgPriceLCCell.innerText = dataItem.get_cell("YOI_AVG_PRICE_DOLLARS").innerText.replace("$", "");
        y1AvgPriceLCCell.innerText = dataItem.get_cell("Y1_AVG_PRICE_DOLLARS").innerText.replace("$", "");

     So, is it possible to change the column to readonly, and back again, using javascript?

    Thank you



  4. Mike
    Mike avatar
    10 posts
    Member since:
    Jan 2014

    Posted 10 Aug 2015 in reply to Mike Link to this post

    I forgot to include an example of the column markup:

                        <telerik:GridBoundColumn  DataFormatString="{0:N2}" DataField="REG_PRICE_LC" DataType="System.Decimal" FilterControlAltText="Filter REG_PRICE_LC column" HeaderText="Suggested Regular Price" SortExpression="REG_PRICE_LC" UniqueName="REG_PRICE_LC">
                            <HeaderStyle Width="75px" BackColor="LightGreen" />
                            <ItemStyle Wrap="False"  HorizontalAlign="Right" />

Back to Top