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

How do you force a column to be read only?

3 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
john
Top achievements
Rank 1
john asked on 21 May 2008, 05:17 AM
Hello,

This should be pretty simple, but I have not found an answer online.

In my grid control, I have a column defined as a  GridTemplateColumn.   Within this, I have of course:  ItemTemplate  and EditItemTemplate.  

Here's my question:  How do I prevent edits for this column --but yet still have it enabled for inserts.  Make sense? 

I want to prevent the user from editing this column value after the record has been created.

Thanks for anyone's help (been stuck on this for sometime),
John

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 21 May 2008, 06:21 AM
Hi,

Try the following code snippet.

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)    
    {    
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode) && (!e.Item.OwnerTableView.IsItemInserted))    
        {    
            GridEditableItem edititem = (GridEditableItem)e.Item;    
            edititem["columnUniqueName"].Enabled = false;    
        }    
    }  

Thanks
Princy.
0
john
Top achievements
Rank 1
answered on 21 May 2008, 06:29 AM
Thanks a bunch Princy, that did it!

Thanks!
0
Shinu
Top achievements
Rank 2
answered on 21 May 2008, 08:02 AM
Hi John,

You can also have a look at the following help article.
Different edit/insert forms with auto-generated edit form

Shinu.
Tags
Grid
Asked by
john
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
john
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or