Hello please i need help on how to get a gridview datakey value of a selected row that is binded manually from a linq to entity query. This is my query i used to bind the gridview
Dim searchClass = From cla In DemoSchool.RealClasses.OrderBy(Function(D) D.ClassCode).ThenBy(Function(P) P.ClassArm) _
Where cla.Session = drpSessionGrid.SelectedItem.Text
Select New With {Key .ClassSN = cla.ClassSN,
Key .Class = cla.ClassCode,
Key .ClassArm = cla.ClassArm}
grdShowClassBySession.DataSource = searchClass
grdShowClassBySession.DataBind()
The query works fine and the data is displayed on the gridview as expected, The problem is that i want to be able to retrieve the datakey of a selected row in the gridview selectedindexchanging method but i can't since the gridview is not bounded by a datasourceID like an entitydataSource control. I found a custom control from this url on codeproject
Simple GridView Radio Button Row Selector[
^] .The control is able to fake the gridview selected row link button by using a radiobutton.But when i use it to get the datakey value of a selectedRow it gives an error saying Object not set to the instance of an object use the New Keyword
Private Sub grdShowClassBySession_SelectedIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdShowClassBySession.SelectedIndexChanging
Dim classS As String = grdShowClassBySession.DataKeys(grdShowClassBySession.SelectedIndex).Value.ToString
End Sub
I have been cracking my head since and i have also passed by bedtime (hope i don't sleep in the office tomorrow) because of this problem.Any help is highly appreciated. If i can be pointed to a more workable solution to this problem i will be very grateful.Thanks as always