Show Selected Data from GridView in TextBox ASP.NET VB
<p>I was working on ASP.NET using VB and encountered the problem by showing the selected data from grid view to text box.
I am not sure whether I do my data binding to textbox is correct or not, here is my code for data binding to text box. For grid view I just direct choose from the data source window. </p>

<p>TextBox data binding code in aspx:</p>

<pre><code>&lt;asp:TextBox Text='&lt;%# Bind("TextData")%&gt;' ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
&lt;asp:TextBox Text='&lt;%# Bind("TextData")%&gt;' ID="TextBox2" runat="server"&gt;&lt;/asp:TextBox&gt;
&lt;asp:TextBox Text='&lt;%# Bind("TextData")%&gt;' ID="TextBox3" runat="server"&gt;&lt;/asp:TextBox&gt;
&lt;asp:TextBox Text='&lt;%# Bind("TextData")%&gt;' ID="TextBox4" runat="server"&gt;&lt;/asp:TextBox&gt;
&lt;asp:TextBox Text='&lt;%# Bind("TextData")%&gt;' ID="TextBox5" runat="server"&gt;&lt;/asp:TextBox&gt;
&lt;asp:TextBox Text='&lt;%# Bind("TextData")%&gt;' ID="TextBox6" runat="server"&gt;&lt;/asp:TextBox&gt;
&lt;asp:TextBox Text='&lt;%# Bind("TextData")%&gt;' ID="TextBox7" runat="server"&gt;&lt;/asp:TextBox&gt;
&lt;asp:TextBox Text='&lt;%# Bind("TextData")%&gt;' ID="TextBox8" runat="server"&gt;&lt;/asp:TextBox&gt;
</code></pre>

<p>I enable the selection on the grid view so that when the row is selected, its data will show in the text box.</p>

<p>The code to show in the text box:</p>

<pre><code>Imports System.Data.SqlClient
Public Class Edit
Inherits System.Web.UI.Page
Public con As New SqlConnection("Data Source=localhost;Initial Catalog=Tuition_Information;Integrated Security=True")
Public cmd As New Data.SqlClient.SqlCommand

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged

End Sub

Protected Sub OnSelectedIndexChanged(sender As Object, e As EventArgs)
    Dim row As GridViewRow = GridView1.SelectedRow
    TextBox1.Text = row.Cells("StudentID").Text
    TextBox2.Text = row.Cells("StudentName").Text
    TextBox3.Text = row.Cells("HomeAddress").Text
    TextBox4.Text = row.Cells("ContactNumber").Text
    TextBox5.Text = row.Cells("SubjectCode").Text
    TextBox6.Text = row.Cells("SubjectName").Text
    TextBox7.Text = row.Cells("ParentName").Text
    TextBox8.Text = row.Cells("ParentContact").Text
End Sub
End Class
</code></pre>

<p>Here is my pages for the view, I want the data show in the textbox so that I can edit it and update to the database. It will also used in delete too.
But when I click the link SELECT, it did not show the data in textbox.</p>

<p><a href="https://i.stack.imgur.com/3kNg4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3kNg4.png" alt="Edit Pages View"></a></p>

<p>What did I do wrong? Please help me, thank you. </p>