Its all in the question really!
My datagrids work fine!
Using visual basic 2010 please help!!!

Dani AI

Generated

's idea is correct: capture the grid row the user clicks and copy the values into the textboxes. Below are short, practical VB.NET WebForms examples (VB2010) and common pitfalls so the solution works reliably.

GridView (recommended) — SelectedIndexChanged

Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
    Dim row As GridViewRow = GridView1.SelectedRow

    ' Use DataKeys for IDs
    TextBoxID.Text = GridView1.DataKeys(row.RowIndex).Value.ToString()

    ' BoundField values (mind the select column: cell indexes may shift)
    TextBoxName.Text = Server.HtmlDecode(row.Cells(2).Text).Trim()

    ' TemplateField values (FindControl for controls inside the cell)
    Dim lblPhone As Label = CType(row.FindControl("lblPhone"), Label)
    If lblPhone IsNot Nothing Then TextBoxPhone.Text = lblPhone.Text
End Sub

DataGrid (older control) — ItemCommand

Protected Sub DataGrid1_ItemCommand(source As Object, e As DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
    If e.CommandName = "Select" Then
        TextBox1.Text = e.Item.Cells(1).Text
        TextBox2.Text = CType(e.Item.FindControl("Label1"), Label).Text
    End If
End Sub

Troubleshooting & tips

  • If a Select button exists, cell indexes shift: verify which column index holds your value or use DataKeys instead.
  • TemplateField must use FindControl; BoundField gives you row.Cells(index).Text.
  • HTML entities (like  ) can make a textbox look empty — use Server.HtmlDecode and .Trim() or replace " ".
  • Do not rebind the grid on every Page_Load (wrap data bind in If Not IsPostBack) or selection will be lost.
  • For paging, prefer DataKeys or include the key in CommandArgument so you can fetch the record regardless of current page.

These patterns will let you copy any row into a set of textboxes cleanly in VB2010 WebForms.

Recommended Answers

All 2 Replies

You need to get the row from grid and loop through the cells And assign to textboxes.

You need to get the row from grid and loop through the cells And assign to textboxes.

Could you gimme the code for that please?:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.