I want to change the text of two labels based on the selected row of a gridview.
I keep getting an error that says the public member row does not exist on linkbutton
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim LinkButton1 As LinkButton = DirectCast(sender, LinkButton)
Dim tour As Label = CType(sender.Row.FindControl("label2"), Label)
Dim depart As Label = CType(sender.Row.FindControl("label3"), Label)
test.Text = tour.Text
test1.Text = depart.Text
According to your code,
sender is a
LinkButton. The property
Row won't exist on a link button when you reference
sender.Row. That's why you get the error.
You want to hook into the SelectedIndexChanged event, which will give you access to the Row more easily.
Sub MyGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Dim myGrid As GridView = TryCast(sender, GridView) Dim selectedRow As GridViewRow = myGrid.SelectedRow 'do something with selected row as needed from here..... End Sub