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

Access Read Only and Hidden Fields in RadGrid (in Edit Mode)

2 Answers 257 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Noha
Top achievements
Rank 1
Noha asked on 25 Oct 2010, 10:50 AM
Dear all

I have a RadGrid contains 3 columns as below:
 
<telerik:GridBoundColumn DataField="ID" HeaderText="ID" 
    ReadOnly="True" UniqueName="column1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Seller" HeaderText="Seller" 
    ReadOnly="True" UniqueName="column2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Amount" HeaderText="Amount" 
    UniqueName="column3">
</telerik:GridBoundColumn>

2 of them are read only and user can only edit in column3.

I get the edited item as below:

But I can't get the value of the first column , the "ID" ?!!!!

protected void grdSellers_ItemCommand(object source, GridCommandEventArgs e)
{
    switch (e.CommandName)
    {
        case "Update":
            GridEditableItem editedItem = e.Item as GridEditableItem;
            TableCell cell = editedItem["column3"];  
            string itemValue = (cell.Controls[0] as TextBox).Text;
              
            //Get Id of editable item ??
    }
}


I tried the solution in this post:
http://www.telerik.com/community/forums/aspnet-ajax/grid/accessing-readonly-hidden-fields-in-edit-mode-radgrid.aspx

but it generate error about ParentItem !

Could any one help me in that issue ??

Regards

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 25 Oct 2010, 11:31 AM
Hello Noha,


One suggestion is setting the DataKeyNames and accessing the value using the "GetDataKeyValue" method. Here is the sample code.
            string itemValue = editedItem.GetDataKeyValue("ID").ToString();


Also the following code worked fine for me.

C#:
protected void grdSellers_ItemCommand(object source, GridCommandEventArgs e)
{
    switch (e.CommandName)
    {
        case "Update":
            GridEditableItem editedItem = e.Item as GridEditableItem;
            TableCell cell = editedItem["column1"];  //access cell using ColumnUniqueName
            string id = (cell.Controls[0] as TextBox).Text;// get id
     }
}


Thanks,
Princy.
0
Noha
Top achievements
Rank 1
answered on 25 Oct 2010, 11:45 AM
Thanks Princy :)
It works.

it looks tricky in that line !!!
string itemValue = (cell.Controls[0] as TextBox).Text;
Tags
Grid
Asked by
Noha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Noha
Top achievements
Rank 1
Share this question
or