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

[?]How to get value of GridDataBound in EditMode

2 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tan
Top achievements
Rank 1
Tan asked on 19 Mar 2012, 12:42 AM
Hi all,
I have a problem with my radGrid. My code below:
======ASPX code=====
<telerik:RadGrid ID="rgData" runat="server" AutoGenerateColumns="false"
                           onupdatecommand="rgData_UpdateCommand1">
            <MasterTableView DataKeyNames="ID" >
            <PagerStyle Mode="NextPrevAndNumeric" />
            <Columns>
                      <telerik:GridBoundColumn  DataField="Name"
                                                            UniqueName="clName"
                                                               HeaderText="Name" >
                      </telerik:GridBoundColumn>
            </Columns>
</telerik:RadGrid>
=====C# code========
protected void rgData_UpdateCommand1(object sender, GridCommandEventArgs e)
        {
            GridEditableItem item = (GridEditableItem)e.Item;
            string value = (item["clName"].Controls[0] as TextBox).Text;
        }
===================
When I debug, I only get value of column Name, not the value I set in edit mode.
this is my Grid:  http://i1068.photobucket.com/albums/u450/bl4ir121/Error_RadGrid.jpg
I try get Kevin value but I only get John value.
Please help me, It's very important.
Thank all.

2 Answers, 1 is accepted

Sort by
0
msigman
Top achievements
Rank 2
answered on 19 Mar 2012, 02:26 AM
Hi Tan,

See if this gets you started:
private void rgData_UpdateCommand1(object source, GridCommandEventArgs e)
{
   GridEditableItem editedItem = e.Item as GridEditableItem;
   Hashtable newValues = new Hashtable();
   e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
   changedRows[0].BeginEdit();
   try
   {
       foreach (DictionaryEntry entry in newValues)
       {
           changedRows[0][(string)entry.Key] = entry.Value;
       }
       changedRows[0].EndEdit();
   }
   catch (Exception ex)
   {
       changedRows[0].CancelEdit();
       Label1.Text += "Unable to update. Reason: " + ex.Message;
       e.Canceled = true;
   }
}


If that is not what you want, you can try the ExtractValues() method as well:
private void rgData_UpdateCommand1(object source, GridCommandEventArgs e)
{
    GridEditableItem ei = ((GridEditableItem)(e.Item));
    Hashtable t1 = new Hashtable();
    ei.ExtractValues(t1);
}
0
Tan
Top achievements
Rank 1
answered on 19 Mar 2012, 04:27 AM
Hello msigman,
First, I thank you so much for ur reply. I already resolve my problem. I call ReBind() in the ItemCommand event without if else statement, so it call ItemCommand event every I click Update button, and ItemCommand event call ReBind(), and the value I set become the value binded in grid.
thanks you again msigman.^^
Tags
Grid
Asked by
Tan
Top achievements
Rank 1
Answers by
msigman
Top achievements
Rank 2
Tan
Top achievements
Rank 1
Share this question
or