Get datakey of selected row for function invoked by buttonfield in a gridview
Posted on 2006-06-22
I want to run a sub when clicking a button in my grid. I want to use the datakey in the function.
I'm doing this...
Protected Sub grvOutGoingTradeStatus_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "SendEmailAcknow" Then
Dim row As GridViewRow = grvOutGoingTradeStatus.Rows(CInt(e.CommandArgument))
Dim id As Integer = grvOutGoingTradeStatus.DataKeys(row.RowIndex).Value
When it gets to Dim id as integer .... it throws an error saying 'index out of range. Must be non negative and less
than the size of the collection. Parameter name: Index'
How do I get the value of the datakey for the selected row, to use in my sub ??