Datagrid buttons not working
-
Hello, I am creating a column of buttons for a datagrid which is bound to a dataset. Some columns of the dataset are not being displayed in the datagrid. When I click a button in the datagrid, I would like to retrieve some information from a hidden column of that particular row of the dataset. Does anyone know how to do this? Is there any way to pass this information? Thanks for your help, RC
-
Hello, I am creating a column of buttons for a datagrid which is bound to a dataset. Some columns of the dataset are not being displayed in the datagrid. When I click a button in the datagrid, I would like to retrieve some information from a hidden column of that particular row of the dataset. Does anyone know how to do this? Is there any way to pass this information? Thanks for your help, RC
Something like the following should work:
Private Sub DataGrid1\_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand If (CType(e.CommandSource, Button)).CommandName = "Select" Then Dim tc As TableCell = e.Item.Cells(2) Dim item As String = tc.Text End If End Sub
What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
-
Something like the following should work:
Private Sub DataGrid1\_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand If (CType(e.CommandSource, Button)).CommandName = "Select" Then Dim tc As TableCell = e.Item.Cells(2) Dim item As String = tc.Text End If End Sub
What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
I actually got it working in a slightly different manner using "e.Item.DataSetIndex". Here is the code I used.
public void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e){ Session ["Variable"] = dataSet1.Tables["Data"].Rows[e.Item.DataSetIndex]["ID"].ToString(); }
Thanks for your help!! -
I actually got it working in a slightly different manner using "e.Item.DataSetIndex". Here is the code I used.
public void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e){ Session ["Variable"] = dataSet1.Tables["Data"].Rows[e.Item.DataSetIndex]["ID"].ToString(); }
Thanks for your help!!