net and C# 4.
I have a DetailsView Control, and I use some custom logic for data binding.
When input data in my DetailsView I would like to use the Event "Inserted" (or another) to get from the DetailsView the Primary Key for the recently inserted data (I suppose using the DataKey properties).
Unfortunately I’m not able to do it.
Do you have any idea how to insert retrive the Primary Key for a item being inserted using the DetailsView?
Thanks for your help!
First of all, your SQL statement needs to return the
SCOPE_IDENTITY().Second, assuming you are using an
ObjectDataSourcecontrol, gete.ReturnValuein your datasource control’sInsertedevent, as in the following example:This example uses the new key value to redirect to the detail page.
If you are using a
SqlDataSourcecontrol, you can programmatically access either Output parameters or ReturnValue parameters, depending on how you wrote the SQL. I’ll make an example if you fill me in on what kind of data access you are using.