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

Retrieve Values after Insert Command

7 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dominic
Top achievements
Rank 2
Dominic asked on 12 Nov 2008, 08:41 PM
Hi

My grid allows automatic operations but i have some other controls (usercontrol in a templateColumn) that i need to extract the values to be able to save some other informations in related tables, so i need the primary key of the inserted item. I've tried to extract the value in the ItemInserted but it seems that the informations are no longer available at this moment... How i can use automatic operations and be able to save other informations who needs the primary key of the inserted item ?

Thanks in advance for your help. If you need more detail about my case, please let me know.

7 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 13 Nov 2008, 07:43 AM
Hello Dominic,

You can use InsertCommand to achieve this.

Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dominic
Top achievements
Rank 2
answered on 13 Nov 2008, 01:15 PM
Hi

I know how to save the new item but i want to know how i can read the Primary key of the last inserted item after the insertitem command ? i'm using the automatic insert to add some item but after that i need to know what is the primary key of the inserted item because i need to save the content of some other usercontrols included in the EditTemplate.

Maybe i'm missing something so if it is the case , please show me how i can read the primarykey of the inserted item ?

Thanks for your help.

0
Daniel
Telerik team
answered on 14 Nov 2008, 08:26 AM
Hello Dominic,

I suggest you examine the following links:
Returning auto generated primary key
Retrieving Identity or Autonumber Values (ADO.NET)

I hope this helps.

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dominic
Top achievements
Rank 2
answered on 14 Nov 2008, 11:41 AM

Hi


Maybe my previous post was not clear. I just want to get the primary key of the last saved item in the grid by using automatic operations , how can i get it ?

Thanks

0
Daniel
Telerik team
answered on 17 Nov 2008, 02:38 PM
Hello Dominic,

For your convenience I created a sample website illustrating what I meant.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dominic
Top achievements
Rank 2
answered on 17 Nov 2008, 03:15 PM

hi

Ok, i know that you can do this but is there a way to do this in one of the Grid event without using the datasource event ?

Thanks

0
Daniel
Telerik team
answered on 20 Nov 2008, 10:15 AM
Hello Dominic,

You can access the auto-generated key on the DataSource event only. The same approach is also used for the standard ASP.NET controls.

Getting the identity of the most recently added record

Let me know if you need more information.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Dominic
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Dominic
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or