retrieve autonumber DataKeyValue on Insert from Codebehind

4 posts, 0 answers
  1. Peter Sitero
    Peter Sitero avatar
    15 posts
    Member since:
    Oct 2009

    Posted 22 Dec 2009 Link to this post

    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.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Dec 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Peter Sitero
    Peter Sitero avatar
    15 posts
    Member since:
    Oct 2009

    Posted 23 Dec 2009 Link to this post

    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.
  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 29 Dec 2009 Link to this post

    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.
Back to Top