RadioButtons

rangerstud620

Freshman
Joined
Jun 14, 2005
Messages
27
I'm sure this is simple to do but I'm stumped. I created an image gallery using a datalist. For each image, there are 2 radiobuttons (Approve, Disapprove). The radiobutton that needs to be checked is determined by the value of a field in a database. For example, if the DB field = "Y", the Approve radiobutton should be checked. If the DB field = "N", the Disapprove radiobutton should be checked. How do I get the correct radiobutton selected? Thanks
 
In your itemdatabound event, something like

Code:
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                Dim rbList As RadiobuttonList = e.Item.FindControl("rbList")
   If e.Item.DataItem("Approve") = "Y" Then
      rbList.Items.FindByValue("Approve").Selected = True
   Else
      rbList.Items.FindByValue("Disapprove").Selected = True
   End If
End If

make sure your radiobutonlist does not have anything selected or else you'll get an error, or unselect anything before you attempt to set an item.
 
Back
Top