Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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
Posted

In your itemdatabound event, something like

 

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...