Read-only controls for editing

5 posts, 2 answers
  1. Eliyahu Goldin
    Eliyahu Goldin avatar
    85 posts
    Member since:
    Apr 2007

    Posted 13 Aug 2008 Link to this post

    In my grid I have some columns that I need to make read-only in the EditingForm. The problem is that setting ReadOnly="true" makes these columns disappear from the editing form.

    <telerik:GridBoundColumn DataField="Description" HeaderText="Delivery Method" SortExpression="Description" ReadOnly="true" /> 
    <telerik:GridDropDownColumn DataField="DeliveryCategory" HeaderText="Delivery Type" UniqueName="DeliveryCategory" 
       DataSourceID="sdsDeliveryCategories" ListTextField="Name" ListValueField="Value" 
       FilterListOptions="AllowAllFilters" DropDownControlType="DropDownList"   
       EnableEmptyListItem="false" ReadOnly="true" 
       /> 
     

    A workaround I am thinking about is to replace GridBoundColumn and GridDropDownColumn with GridTemplateColumns, put a textbox and a dropdown list inside and set for them Enabled=false. Is there an easier way?
  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Aug 2008 Link to this post

    Hello Eliyahu,

    Other possible approach is to set ReadOnly programatically in ItemCreated:

    if(e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        ((e.Item as GridEditableItem)["YourBoundColumnUniqueName"].Controls[0] as TextBox).ReadOnly = true;
    }

    Greetings,
    Vlad
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Aug 2008 Link to this post

    Hello Eliyahu,

    I would suggest you to disable the TextBox of the GridBoundColumn and DropDownList of the DropDownColumn, when in EditMode as shown below rather than using TemplateColumns.

    aspx:
      <telerik:GridBoundColumn DataField="ProductID" DataType="System.Int32" HeaderText="ProductID" UniqueName="ProductID"
      </telerik:GridBoundColumn> 
      <telerik:GridDropDownColumn HeaderText="UnitPrice" DropDownControlType="DropDownList" UniqueName="UnitPrice" DataSourceID="SqlDataSource1" ListValueField="UnitPrice" ListTextField="UnitPrice" DataField="UnitPrice"
      </telerik:GridDropDownColumn> 

    cs:
     protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
            { 
                GridEditableItem edititem = (GridEditableItem)e.Item; 
                TextBox txtbx = (TextBox)edititem["ProductID"].Controls[0]; 
                txtbx.Enabled = false
                DropDownList ddl = (DropDownList)edititem["UnitPrice"].Controls[0]; 
                ddl.Enabled = false
            } 
        } 

    Thanks
    Princy.

  5. Eliyahu Goldin
    Eliyahu Goldin avatar
    85 posts
    Member since:
    Apr 2007

    Posted 14 Aug 2008 Link to this post

    Thanks, Vlad and Princy!
  6. aabdan
    aabdan avatar
    26 posts
    Member since:
    Apr 2007

    Posted 11 Oct 2008 Link to this post

    this is ok. But i need it diasabled in edit and insert
    i need it just in edit

    Best regards
    Ahmad
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017