• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 995
  • Last Modified:

How to set RadioButtonList value via table

Hi, I have a radio button with the following code

<legend>Garage:</legend>
<asp:RadioButtonList  runat="server" ID="radioGarage">
<asp:ListItem Value="1" >Yes</asp:ListItem>
<asp:ListItem Value="2" Selected="True">No</asp:ListItem>
</asp:RadioButtonList>

I don't know how to change the selected value based upon a database request.

It's part of a formview, which is:
<asp:FormView ID="AdFormView" runat="server" DataSourceID="AdDataSource" DefaultMode="Edit"
DataKeyNames="Id" OnItemUpdating="AdFormView_ItemUpdating">

I'm not even sure what I should be saving to the database, other texts and labels are using Bind, i.e..

'<%# Bind("Garage") %>'
0
Netlink2
Asked:
Netlink2
  • 2
  • 2
1 Solution
 
Sammy AgeilCommented:
use the SelectedValue property to bind the list to datafield

<legend>Garage:</legend>
<asp:RadioButtonList  runat="server" ID="radioGarage" SelectedValue='<%# Bind("YOUR_DATA_FIELD_NAME") %>'>
<asp:ListItem Value="1" >Yes</asp:ListItem>
<asp:ListItem Value="2" Selected="True">No</asp:ListItem>
</asp:RadioButtonList>
0
 
Qaiser_Mehmood_MughalCommented:
Use Databound property of this control and also then set the selected value at code behind
0
 
Netlink2Author Commented:
Thanks Qaiser, I suppose the question is how do I do this ?. Can you provide an example in code ?.
0
 
Qaiser_Mehmood_MughalCommented:
0
 
Netlink2Author Commented:
I gave up on trying and just used checkboxes instead.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now