The reason is obvious: you are destroing previous data every time when you call procedure
GridView1_SelectedIndexChanged
.
Move this line
Dim dogTags As New DataTable()
outside the procedure (for example: after
InitializeComponent
method).
Then change your procedure this way:
Protected Sub GridView1_SelectedIndexChanged(Id As Integer, Name As String, Owner As Integer)
Dim dt As DataTable = DirectCast(GridView1.DataSource, DataTable)
Dim row As DataRow = dt.NewRow()
row("DogId") = Id
row("Name") = Name
row("Owner") = Owner
dogTags.Rows.Add(row)
GridView1.DataSource = dogTags
End Sub
In a meanwhile. please read this:
Scope in Visual Basic | Microsoft Docs[
^]
Variable and Method Scope in Microsoft .NET[
^]
How to: Control the Scope of a Variable (Visual Basic) | Microsoft Docs[
^]
DirectCast Operator (Visual Basic) | Microsoft Docs[
^]
How to: Add Rows to a DataTable[
^]