Hi there,
I keep running into problems with the RadioButtonList.
I have a RBL inside a repeater control. At run time, the list is bound to
data from a DataSet. After I bind the data, I need to preselect an item,
but I can't get it to work.
Here is the relevant part of my code:
Dim aRadioButtonList As RadioButtonList = _
CType(e.Item.FindControl("lstAnswerDate"), RadioButtonList)
aRadioButtonList.DataSource = MyDataSet
aRadioButtonList.DataTextField = "MyColumn"
aRadioButtonList.DataValueField = "MyColumn"
aRadioButtonList.DataBind()
If Not tr.Row(8) Is DBNull.Value Then
Dim aListItem As ListItem
For Each aListItem In aRadioButtonList.Items
If aListItem.Value = tr.Row(8) Then
aListItem.Selected = True
Exit For
End If
Next
End If
tr.Row(8) contains the value I am comparing against.
I stepped through the code and it actually hits the aListItem.Selected =
True. When I look at the RBL in the watch window, I can see the
SelectedIndex is changed to 4 which is what it should be. However, it
doesn't preselect the radio button in the browser.
I also tried to set the SelectedIndex property of the RadioButonList, but
that didn't work either.
The exact same code without the RBL inside a Repeater control works as
expected.
What is going on????
Thanks in advance for any help.
Imar