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

retrieve autonumber DataKeyValue on Insert from Codebehind

3 Answers 21 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter Sitero
Top achievements
Rank 1
Peter Sitero asked on 22 Dec 2009, 08:55 PM
I am unable to retrieve the DataKeyValue on Insert so I can reference the saved record from the code behind to do further processing.  How is this accomplished?
I have used the editeditem.datakeyvalues(e.item.itemindex)("ThisIDFieldName") with an index out of range error.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 23 Dec 2009, 05:55 AM
Hi Peter,

Checkout the following code library that shows how to access the last inserted record in PreRender event. I hope this will help you.
Select Last Inserted Row

-Shinu.
0
Peter Sitero
Top achievements
Rank 1
answered on 23 Dec 2009, 03:48 PM
If I'm not mistaken this solution assumes no one else is inserting records using another connected session as this code will only return the last record inserted.  Doesn't appear to be air tight.  The control should capture this as a parameter during the insert like the old fassion ADO method and produce it's value if queried.
0
Tsvetoslav
Telerik team
answered on 29 Dec 2009, 08:23 AM
Hi Peter,

Below is the code for accessing the inserted item's data key value in the ItemCommand event:

protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
    string idFieldName = ((GridEditFormInsertItem)e.Item).GetDataKeyValue("ThisIDFieldName").ToString();
}

I hope this helps.

Greetings,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Peter Sitero
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Peter Sitero
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or