How to set selected row in ASP.NET GridView based on DataKey

asp.netgridview

I want something similar to the following pseudocode:

myGridView.SelectedIndex = myGridView.DataKeys.IndexOf("mySpecificKey");

I've done some Intellisense exploring, but I haven't found an obvious way to do this. I would want to set SelectedIndex to -1 if DataKey was not found.

Best Solution

I've ended up with

        For n As Integer = 0 To myGridView.DataKeys.Count - 1
            If myGridView.DataKeys(n).Value = myKeyObj Then
                myGridView.SelectedIndex = n
            End If
        Next