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

Read-only controls for editing

4 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eliyahu Goldin
Top achievements
Rank 1
Eliyahu Goldin asked on 13 Aug 2008, 06:57 PM
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?

4 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 14 Aug 2008, 05:11 AM
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.
0
Accepted
Princy
Top achievements
Rank 2
answered on 14 Aug 2008, 06:06 AM
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.

0
Eliyahu Goldin
Top achievements
Rank 1
answered on 14 Aug 2008, 08:37 AM
Thanks, Vlad and Princy!
0
aabdan
Top achievements
Rank 1
answered on 11 Oct 2008, 10:22 AM
this is ok. But i need it diasabled in edit and insert
i need it just in edit

Best regards
Ahmad
Tags
Grid
Asked by
Eliyahu Goldin
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Princy
Top achievements
Rank 2
Eliyahu Goldin
Top achievements
Rank 1
aabdan
Top achievements
Rank 1
Share this question
or