Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Binding data to radiobutton in a FormView

Reply
Thread Tools

Binding data to radiobutton in a FormView

 
 
sck10
Guest
Posts: n/a
 
      06-28-2006
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>


 
Reply With Quote
 
 
 
 
neilmcguigan@gmail.com
Guest
Posts: n/a
 
      06-28-2006
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


sck10 wrote:
> 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>


 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      06-29-2006
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 ((E-Mail Removed), 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.

 
Reply With Quote
 
sck10
Guest
Posts: n/a
 
      06-30-2006
Thanks Walter...


"Walter Wang [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 ((E-Mail Removed), 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.
>



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      07-03-2006
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 ((E-Mail Removed), 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET FormView Money Data Type Binding Problem with 2 Decimal Points.. Sam ASP .Net 1 02-11-2010 02:22 PM
Ajax TabContainer inside a FormView - Data binding Update doesn't Colorstone ASP .Net 2 10-07-2008 09:39 PM
Formview (EditView) Money Data Type Binding problem. Help.... Sam ASP .Net Web Controls 0 06-16-2006 11:32 PM
FormView/Repeater/ Eval(FormView data) David Thielen ASP .Net Web Controls 2 06-16-2006 07:56 PM
FormView and stored proc data binding =?Utf-8?B?SmVmZiBIYXJrYXZ5?= ASP .Net 0 06-09-2006 03:13 PM



Advertisments