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

Column read only in edit mode, editable in insert mode

1 Answer 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 2
Nick asked on 18 Jun 2012, 08:14 PM
I want to make a column readonly when editing, but if I am inserting a new entry I don't want the column to be readonly. How can I do this when my columns are generated using an sql datatable?

-Nick

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Jun 2012, 03:23 AM
Hi Nick,

Try the following code snippet to make a column ReadOnly in edit mode and editable in insert mode.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode && !(e.Item is GridEditFormInsertItem))
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        TextBox txt = (TextBox)editedItem["UniqueName"].Controls[0];
        txt.ReadOnly = true;
    }
}

Thanks,
Princy.
Tags
Grid
Asked by
Nick
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or