title: VB.net Gridview DataKeys for information display
body: <p>I am trying to select a row from my gridview and then display further information associated with the data from the row. In order to do this I am setting a DataKey which in this case is ID. I then want to access my database and select all the records where the ID is equal to the ID which is the DataKey of the selected row. I am having a bit of trouble with this unfortunately as I am not aware  how to correctly access the DataKey of my Selected row. Below is my code. I am trying to take the value of the datakey and set it as an int, which then in return is used in my SELECT statement. </p>
  
  <pre><code>     Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
      Dim RegDataConn1 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" &amp; Server.MapPath("App_Data/1202389.mdb"))
      Dim i As Integer = GridView1.SelectedIndex
      Dim hotelid As Integer = GridView1.DataKeys(i).Value
  
  
  
  
      Dim cmd1 As OleDbCommand = New OleDbCommand("SELECT * FROM Ratings WHERE Hotel.Hotel_ID=" &amp; hotelid.ToString(), RegDataConn1)
      RegDataConn1.Open()
      Dim myDA1 As OleDbDataAdapter = New OleDbDataAdapter(cmd1)
      Dim myDataSet1 As DataSet = New DataSet
      myDA1.Fill(myDataSet1, "Table1")
      GVDetailView.DataSource = myDataSet1.Tables("Table1").DefaultView
      GVDetailView.DataBind()
      RegDataConn1.Close()
  
  End Sub
  </code></pre>
  
  <p><a href="http://postimg.org/image/yp3ukwsdv/" rel="nofollow">http://postimg.org/image/yp3ukwsdv/</a> Here is a picture of my error</p>