473,324 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Binding data to radiobutton in a FormView

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>
Jun 28 '06 #1
4 12048
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>


Jun 28 '06 #2
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 (wa****@online.microsoft.com, 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.

Jun 29 '06 #3
Thanks Walter...
"Walter Wang [MSFT]" <wa****@online.microsoft.com> wrote in message
news:Rv**************@TK2MSFTNGXA01.phx.gbl...
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 (wa****@online.microsoft.com, 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.

Jun 30 '06 #4
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 (wa****@online.microsoft.com, 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.

Jul 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Rourke Eleven | last post by:
I have looked and searched. What good is the databind property on Radiobuttons? How does one go about actually using it? What is a good resource on this? I understand that I can easily get/set...
0
by: Steven Blair | last post by:
Hi, A bit long winded this one, but would be grateful for some help. I have a problem using the Wizard component and can think of only two ways of completing the task. Can anyone with some...
0
by: AM | last post by:
The following block of code defines a FormView control "FormView1" with an EditItemTemplate which has a Label and a TextBox control within it. While the Label "RequestIDLabel1" has one-way...
0
by: sercanparlak | last post by:
Hi, I have a problem with binding. I want to bind a field in my database to a radiobutton. I achieve this with this code this.radioButton1.DataBindings.Add(new...
3
by: Wilson | last post by:
Hi, Can I do data binding for a textbox in a webform at server side ? not using the Data Binding Expression. Thanks Wilson
3
by: cannontrodder | last post by:
I am displaying names and other details of my users in a Formview control by binding my custom business object to it. My custom object also has a property that is a collection of boolean values and...
8
by: =?Utf-8?B?QXNo?= | last post by:
Hi, I have an object, for example User. User contains various properties which i have been able to bind to successfully using wizards and the form view. However if the class User has a property...
0
by: =?Utf-8?B?TWlrZSBNaWxpYW4=?= | last post by:
I have a dropdownlist control in a formview and I am trying to enable 2 way databinding. Only, the option is not available. I look at the "Edit Databinding" option of another DDL control in the...
2
by: =?Utf-8?B?Q29sb3JzdG9uZQ==?= | last post by:
Hi, I have a TabContainer inside a data bound FormView (to logically group the form fields into different tabs). The display part of the data binding works fine, but the Update doesn't. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.