I'm using "e.Index.ItemIndex" to get the row number that was clicked for deletion in my datagrid. How can I obtain the primary key of the row to use in my query to delete the record from the database?
Printable View
I'm using "e.Index.ItemIndex" to get the row number that was clicked for deletion in my datagrid. How can I obtain the primary key of the row to use in my query to delete the record from the database?
well, I'm going to answear my own question...hope this helps others..
Set the DataKeyField property of the Datagrid to the name of the primary key. Then on the delete event set a variable to the index of the DataKeyField, example:
Dim ID As Integer = CInt(MyGrid.DataKeys(CInt(e.Item.ItemIndex)))
Then pass this variable into the query or stored procedurer.
eye