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

How to get the deleted/edited item in Grid?

4 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Viktor Takacs
Top achievements
Rank 2
Viktor Takacs asked on 18 Jun 2011, 01:08 PM
Hi,

I used to work with Telerik's controls some time ago, but after a few years of gap it seems I have forgotten some...

I have a Grid bound to a List<myTypeClass>. When I click on Edit/Delete, in the event handlers (RadGrid1_UpdateCommand and RadGrid1_DeleteCommand) I can't seem to figure out how to get the item that was edited/deleted.
I have custom stored procudures doing all the CRUD operations and to delete an item, for example, I need to know it's ID (which is one of the properties of the items in the list.
Any idea?
Any ideas are much appreciated
v

4 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Jun 2011, 01:15 PM
Hi,

<MasterTableView DataKeyNames="ID">
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GridEditableItem item = (GridEditableItem)e.Item;
           //  Get Edit Row's ID
            int ID = Convert.ToInt32(item.GetDataKeyValue("ID"));
 
        }
protected void Radgrid1_DeleteCommand(object source, GridCommandEventArgs e)
    {
        GridDataItem item = (GridDataItem)e.Item;
 
        int ID = Convert.ToInt32(item.OwnerTableView.DataKeyValues[item.ItemIndex]["ID"].ToString());
    }


Thanks,
Jayesh Goyani
0
Viktor Takacs
Top achievements
Rank 2
answered on 18 Jun 2011, 01:35 PM
Thank you for the prompt and accurate reply, Jayesh. Apparently, I just missed this part from my story:
<MasterTableView DataKeyNames="ID">

One more (related) question though: In the UpdateCommand handler how do I get the new value? On which control do I have to start looking? In this simple example just the inline editor is fine for me.
Thanks again!
0
Accepted
Shinu
Top achievements
Rank 2
answered on 18 Jun 2011, 02:02 PM
Hello Viktor,

Give a try with the following code snippet as described in this help article to get the new value.

ASPX:
<telerik:GridBoundColumn DataField="FirstName"  UniqueName="FirstName">
</telerik:GridBoundColumn>

C#:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
   {
       GridEditableItem editedItem = e.Item as GridEditableItem;
       Hashtable newValues = new Hashtable();
       e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
       string v=  newValues["FirstName"].ToString();//getting new value
   }

-Shinu.
0
Viktor Takacs
Top achievements
Rank 2
answered on 18 Jun 2011, 05:25 PM
Hi Shinu,

Thank you, this works as I expected.

cheers
v
Tags
Grid
Asked by
Viktor Takacs
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Viktor Takacs
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or