Binding data to radiobutton in a FormView

S

sck10

Hello,

I am trying to use a radiobutton inside of a FormView for editing data. My
question is how do you bind the radio buttons to the data field? Thanks,
sck10



<td style="width:30%; text-align:center;">
<asp:RadioButton id="rbn01Approved" runat="server"
Text="Approved"
TextAlign="left"
GroupName="rbn02"
Checked="False"/></td>

<td style="width:50%; text-align:left;">
<asp:RadioButton id="rbn01Denied" runat="server"
Text="Denied"
TextAlign="Right"
GroupName="rbn02"
Checked="False"/></td>
 
N

neilmcguigan

you'll have to fill the radiobuttonlist with data, either enter
manually, or from another data source

to hook it up with the data in for your formview:

you can set

SelectedValue='<%# Eval("Some Field In Your Formview Datasource") %>'

or

SelectedIndex='<%# Eval("Some Field In Your Formview Datasource") %>'

cheers

neil
 
W

Walter Wang [MSFT]

Hi,

Thank you for your post.

You can use RadioButtonList and its DataBinding event to do this. Using
SqlServer database Northwind's Products for example:

<asp:RadioButtonList ID="rlist1"
OnDataBinding="RadioButtonList1_DataBinding" runat="server">
<asp:ListItem Text="Discontinued"></asp:ListItem>
<asp:ListItem Text="In Stock"></asp:ListItem>
</asp:RadioButtonList>

protected void RadioButtonList1_DataBinding(object sender, EventArgs e)
{
RadioButtonList rlist = (RadioButtonList) sender;
bool discontinued = (bool) DataBinder.Eval(rlist.BindingContainer,
"DataItem.Discontinued");
string text = "In Stock";
if (discontinued)
{
text = "Discontinued";
}
foreach(ListItem li in rlist.Items)
{
if (li.Text == text)
{
li.Selected = true;
break;
}
}
}

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

You're welcome!

If you have any other questions or concerns, please do not hesitate to
contact us. It is always our pleasure to be of assistance.

Have a nice day!

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top