I am adding a list of radiobutton lists dynamically to the page and on button click I want to store the selected values .i am following this sample code below. How can I retrieve the selectedIndexes of these dynamically created RadioButtonLists? I've spent the better part of the day trying various fixes from other similar questions online, but have had no luck. If I use 'Inspect Element' in Chrome, I am able to see the RadioButtonLists in their desired locations ostensibly with the ID I have assigned (RBQuestion_1, RBQuestion_2, etc),
Sub BindForm()
Dim tblStars As New Table()
Dim rb As New RadioButtonList()
rb.ID = RBQuestion_" & row("Id")
Dim tc As New TableCell()
Dim tr As New TableRow()
tc.Controls.Add(rb)
tr.cells.Add(tc)
tblStars.Rows.Add(tr)
form1.Controls.Add(tblStars)
Next
end sub
Protected Sub btnSave_click(ByVal sender As Object, ByVal e As EventArgs)
For Each ctrl As Control In Page.FindControl(RBQuestion_" & row("Id"))
If TypeOf ctrl Is RadioButtonList Then
Dim rbl As RadioButtonList = DirectCast(ctrl, RadioButtonList)
For i As Integer = 0 To rbl.Items.Count - 1
If rbl.Items(i).Selected Then
'get the value of the selected radio button'
Dim value As String = rbl.SelectedItem.Value
End If
Next
End If
Next
end sub