Obtaining Cell value of Datagrid using Select Button on the SelectedIndexChanged Event

I have a datagrid that I want an event to fire when user hits the select button.  I have put a select button on the datagrid and then put some code in the SelectedIndexChanged event handler for that datagird.   All i am trying to do is get the keyfield value from the selected item of the datagrid.   e arg has no elements to reference cell or control values in the selected row of the data grid.   I therefore am trying the following code to try to get at the value of this keyfield.   The Keyfield is on the first cell (0).   and here is what I am to do.  I want to assign the variable "fileID" to the value of the selected row item so I can use that to pass to by SQL command.

    Private Sub DataGrid2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid2.SelectedIndexChanged
        Dim fileID As Integer
        fileID = Me.DataGrid2.SelectedItem.Cells(0).FindControl(0)????????
    End Sub

I have taken two approches.  One was to access the cell value directly.  The other was to convert that column on the datagrid to a template and put the value in a label  "lblFileID"

Since the e arg give very little to work with on this handler, what would be the best way to handle this situation.

Who is Participating?
Try this:
fileID = Me.DataGrid2.SelectedItem.Cells(0).Text
jholmes724Author Commented:
Thanks that work.  I forgot I had changed it to a templat column.  Once I changed it back to a normal column your code line work.  Thank you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.