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

Columns not getting disabled while in edit mode

2 Answers 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bhavik
Top achievements
Rank 1
Bhavik asked on 27 Oct 2010, 01:17 AM
Hi Guys,

I am trying to disable a column when I click on "Edit" command. In my grid, the Edit command is autogenerated and columns are also autogenerated.

I want to disable a column when I click on "Edit" link. However, the column remains enabled and editable. Can anyone please let me know what am I doing wrong. Following is the code:

 

 

protected void RadGrid_EditCommand(object sender, GridCommandEventArgs e)

{

 

 

    GridDataItem dataItem = e.Item as GridDataItem 

 

 

    var column = RadGrid.MasterTableView.AutoGeneratedColumns.First(i => i.HeaderText == "Name");  

    dataItem[column].Enabled = 

 

false;  

 

 

}

 

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Oct 2010, 05:36 AM
Hello Bhavik,

You can achieve this by accessing the control (which you wants to disable) in ItemDataBound event  and set its enabled property as 'False'.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode)// if EditMode is 'EditForms'
       {
           GridEditFormItem editItem = (GridEditFormItem)e.Item;
           TextBox txt = (TextBox)editItem["Name"].Controls[0];
           txt.Enabled = false;
       }
    }

Thanks,
Princy.
0
Bhavik
Top achievements
Rank 1
answered on 27 Oct 2010, 07:33 PM
Thanks Princy. It worked.
Tags
Grid
Asked by
Bhavik
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bhavik
Top achievements
Rank 1
Share this question
or