Reputation: 168
I have a dropdown in my Repeater that is populated based on which row is selected inside a Gridview that is nested within the Repeater.
I need the dropdown to refresh based on what row is selected in the GridView.
Usually I could get the currently selected row like this:
Protected Sub GvRevisionInfo2_OnSelectedIndexChanged(sender As Object, e As EventArgs)
Dim country As String = TryCast(GridView1.SelectedRow.FindControl("lblCountry"), Label).Text
End Sub
But I don't know the ID of the GridView because it's generated dynamically inside the Repeater. Sometimes there's 2 GridViews other times there is 20.
So how do I get the values from the currently selected row inside a dynamically generated GridView in the codebehind?
Upvotes: 2
Views: 309
Reputation: 35514
You can cast the sender
back to a GridView and use that.
Protected Sub GvRevisionInfo2_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim gridView As GridView = CType(sender,GridView)
Dim label As Label = CType(gridView.SelectedRow.FindControl("lblCountry"),Label)
Dim country As String = label.Text
End Sub
Upvotes: 2