2

I have a datagrid and I want the data in the selected row to be shown in a textbox. I am using .NET 2003. All I found is the solution for datagridview. I tried this code and also SelectedRows but the function does not exist in datagrid.

Private Sub Grid2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Grid2.SelectedIndexChanged
    Dim i, j As Integer
    i = Grid2.CurrentRow.Index
    TextBox1.Text = Grid2.Item(0, i).Value
    TextBox2.Text = Grid2.Item(1, i).Value
    TextBox3.Text = Grid2.Item(2, i).Value
    TextBox4.Text = Grid2.Item(3, i).Value
End Sub
3
  • sorry i copy the wrong code. this is the real code. actually grid2 is a data grid and not datagridview. so i try to change datagridview as grid2 but error Commented Sep 29, 2016 at 1:08
  • the error is at 'CurrentRow' is not a member of data grid Commented Sep 29, 2016 at 1:12
  • Grid2 is a DataGrid. because i using asp.net Commented Sep 29, 2016 at 1:14

1 Answer 1

4

Try this:

Private Sub Grid2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Grid2.SelectedIndexChanged
    TextBox1.Text = Grid2.SelectedItem.Cells(0).Text
    TextBox2.Text = Grid2.SelectedItem.Cells(1).Text
    TextBox3.Text = Grid2.SelectedItem.Cells(2).Text
    TextBox4.Text = Grid2.SelectedItem.Cells(3).Text
End Sub
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! It works. how can i transfer the value in to a different page? because i would like display the data on different page when user click the button
Kindly mark this as answered if it works by clicking the check button.
Regarding that, you can use Session().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.