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

Making a field not editable in a grid

3 Answers 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brendan Vogt
Top achievements
Rank 1
Brendan Vogt asked on 10 Jul 2008, 07:52 AM
Hi,

I have a grid in which the rows can be edited.  When I click on the Edit link a row goes into edit mode.  But there are certain fields that I don't want edited.  Instead of it putting the value into a textbox for edit, I just want a label control there with the value in to.  How do I do this?

Here is my pice of code:

<radG:GridBoundColumn
   UniqueName="CurrentAccountNumber"
   DataField="CurrentAccountNumber"
   HeaderText="Current Account Number" />

Thanks
Brendan

3 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 10 Jul 2008, 07:55 AM
Hi Brendan,

You can set ReadOnly to true to achieve this.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Shinu
Top achievements
Rank 2
answered on 10 Jul 2008, 09:29 AM
Hi Brendan,

You can also try the following approach if you want to put a label instead of the TextBox in edit mode for GridBoundColumn.

CS:
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))  
        {  
            GridEditableItem edititem = (GridEditableItem)e.Item;  
            Label lbl = new Label();  
            lbl.ID="Label1";  
            TextBox txtbx = (TextBox)edititem["CurrentAccountNumber"].Controls[0];  
            lbl.Text = txtbx.Text;  
            edititem["CurrentAccountNumber"].Controls.Clear();  
            edititem["CurrentAccountNumber"].Controls.Add(lbl);  
        }  
          
    }  
 

Thanks
Shinu.
0
Brendan Vogt
Top achievements
Rank 1
answered on 10 Jul 2008, 10:11 AM
Thanks.

I have another question.  When I insert a new record, all the columns marked as read only don't display any text.  I need it to be populated with default text.  How do I do this?

Thanks
Brendan
Tags
Grid
Asked by
Brendan Vogt
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Shinu
Top achievements
Rank 2
Brendan Vogt
Top achievements
Rank 1
Share this question
or