Get key from current record in detailsview, itemdelete

jdkoelewijn used Ask the Experts™
Hi guys,
Before I want to delete a record, first I'd like to check it's references to other tables.
Can someone tell me how to get the current value of the key.
I'm programming in VB.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013
Could be something like this:
1: set property DataKeyNames="Id" to your DetailsView
//Note ..Id is the primarykey field of your set accordingly

Then use ItemDeleting event...

Protected Sub DetailsView1_ItemDeleting(ByVal sender As Object, ByVal e As DetailsViewDeleteEventArgs)
    Dim s As String = DetailsView1.DataKey("Id").ToString()
   'now you have the ID you can do your checking here..
    ' if something wrong cancel the event...
    ' e.Cancel
End Sub



Great! thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial