Binding data to radiobutton in a FormView

  • Thread starter Thread starter sck10
  • Start date Start date
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>
 
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
 
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.
 
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.
 
Back
Top