473,396 Members | 2,076 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,396 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 12058
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.