Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Preselecting an item in a radiobuttonlist


Message #1 by Imar Spaanjaars <Imar@S...> on Thu, 16 Jan 2003 17:30:17 +0100
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



  Return to Index