Link to home
Start Free TrialLog in
Avatar of Netlink2
Netlink2

asked on

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") %>'
Avatar of Sammy
Sammy
Flag of Canada image

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>
Use Databound property of this control and also then set the selected value at code behind
Avatar of Netlink2
Netlink2

ASKER

Thanks Qaiser, I suppose the question is how do I do this ?. Can you provide an example in code ?.
ASKER CERTIFIED SOLUTION
Avatar of Qaiser_Mehmood_Mughal
Qaiser_Mehmood_Mughal
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I gave up on trying and just used checkboxes instead.