Obtaining Cell value of Datagrid using Select Button on the SelectedIndexChanged Event
Posted on 2006-04-28
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)????????
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.