DetailsView How to retrieve a DataKeyNames after an item has been inserted

639 Views Asked by At

I have a DetailsView control with DataKeyNames="JobId" (Primary Key for my DB table).

When a row has been inserted OnItemInserted I need to retrieve the JobId just created and use in some code.

I am not able to do it... Could you please post a easy example?

2

There are 2 best solutions below

0
On

My solution was to Use DetailsView in association with a EntityDataSource. An apply code in event OnItemInserted for the EntityDataSource instead that DetailsView. So it is possible to cast an Entity to a Context Object and use the value JobId just created. Hope can help someone else.

0
On

You haven't provided a lot of usefull information regarding to this case: which database you have used, in which way you get the data and so on. So I can suggest you only take a look at http://msdn.microsoft.com/en-us/library/ks9f57t0.aspx there is a lot of samples how to overcome this issue.