473,388 Members | 1,234 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,388 software developers and data experts.

Assign database value to a RadioButtonList control

Hi, i have a small problem with assigning a database value to a
RadioButtonList control. On my form i have 3 user admin=1, premium=2 and
basic=3, theese values is stored in an access database in a text string.

My problem is that when i'm loading my form, it uses a repeater control
for each user by the way, I can't find a way to assign either of these
values to the RadioButtonList Control. I can read them from the database
but i wan't the ListItem to be set checked correct for each user...here
is some code...

*.aspx form
....
<asp:RadioButtonList ID="rdbtlstLevel" RepeatDirection="Vertical"
ToolTip="Admin" runat="server">
<asp:ListItem Value=1>Admin</asp:ListItem>
<asp:ListItem Value=2>Premium</asp:ListItem>
<asp:ListItem Value=3>Basic</asp:ListItem>
</asp:RadioButtonList>
.....

*.cs form
....
this.rpUser.DataSource = objDS.Tables["tblOrganisation"].DefaultView;
switch (objDS.Tables["tblOrganisation"].Rows["Level"].ToString())
{

case "1": this.rdbtlstLevel.Items[0].Selected = true;
break;
case "2":
this.rdbtlstLevel.Items[1].Selected = true;
break;
case "3":
this.rdbtlstLevel.Items[2].Selected = true;
break;
}
this.rpUser.DataBind();
....

Hence what I wan't to do is to get the values 1,2,3 from access,
transform them to either true or false and then set The correct ListItem
to checked on the *.aspx form for each user.

Any hint from someone??

//Michael
Mar 8 '06 #1
2 4707
Hello Michael,

Bind your RadioButtonList to the method, that returns the list of user-types
like:
<asp:RadioButtonList id="ddd" DataSource="<%# BindTheDiscontinued() %>" DataTextField="Discontinued"
DataValueField="Discontinued" runat="server" />

protected SqlDataReader BindTheDiscontinued()

{
strSql ="SELECT bla-bla-bla" ;
// connect to get data
return dr;
}

MB> Hi, i have a small problem with assigning a database value to a
MB> RadioButtonList control. On my form i have 3 user admin=1, premium=2
MB> and basic=3, theese values is stored in an access database in a text
MB> string.
MB>
MB> My problem is that when i'm loading my form, it uses a repeater
MB> control for each user by the way, I can't find a way to assign
MB> either of these values to the RadioButtonList Control. I can read
MB> them from the database but i wan't the ListItem to be set checked
MB> correct for each user...here is some code...
MB>
MB> *.aspx form
MB> ...
MB> <asp:RadioButtonList ID="rdbtlstLevel" RepeatDirection="Vertical"
MB> ToolTip="Admin" runat="server">
MB> <asp:ListItem Value=1>Admin</asp:ListItem>
MB> <asp:ListItem Value=2>Premium</asp:ListItem>
MB> <asp:ListItem Value=3>Basic</asp:ListItem>
MB> </asp:RadioButtonList>
MB> ....
MB>
MB> *.cs form
MB> ...
MB> this.rpUser.DataSource =
MB> objDS.Tables["tblOrganisation"].DefaultView;
MB> switch (objDS.Tables["tblOrganisation"].Rows["Level"].ToString())
MB> {
MB> case "1": this.rdbtlstLevel.Items[0].Selected = true;
MB> break;
MB> case "2":
MB> this.rdbtlstLevel.Items[1].Selected = true;
MB> break;
MB> case "3":
MB> this.rdbtlstLevel.Items[2].Selected = true;
MB> break;
MB> }
MB> this.rpUser.DataBind();
MB> ...
MB> Hence what I wan't to do is to get the values 1,2,3 from access,
MB> transform them to either true or false and then set The correct
MB> ListItem to checked on the *.aspx form for each user.
MB>
MB> Any hint from someone??
MB>
MB> //Michael
MB>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Mar 8 '06 #2
Michael Nemtsev skrev:
Hello Michael,

Bind your RadioButtonList to the method, that returns the list of
user-types
like:
<asp:RadioButtonList id="ddd" DataSource="<%# BindTheDiscontinued() %>"
DataTextField="Discontinued" DataValueField="Discontinued"
runat="server" />

protected SqlDataReader BindTheDiscontinued()
{ strSql ="SELECT bla-bla-bla" ;
// connect to get data
return dr; }
MB> Hi, i have a small problem with assigning a database value to a
MB> RadioButtonList control. On my form i have 3 user admin=1, premium=2
MB> and basic=3, theese values is stored in an access database in a text
MB> string.
MB> MB> My problem is that when i'm loading my form, it uses a repeater
MB> control for each user by the way, I can't find a way to assign
MB> either of these values to the RadioButtonList Control. I can read
MB> them from the database but i wan't the ListItem to be set checked
MB> correct for each user...here is some code...
MB> MB> *.aspx form
MB> ...
MB> <asp:RadioButtonList ID="rdbtlstLevel" RepeatDirection="Vertical"
MB> ToolTip="Admin" runat="server">
MB> <asp:ListItem Value=1>Admin</asp:ListItem>
MB> <asp:ListItem Value=2>Premium</asp:ListItem>
MB> <asp:ListItem Value=3>Basic</asp:ListItem>
MB> </asp:RadioButtonList>
MB> ....
MB> MB> *.cs form
MB> ...
MB> this.rpUser.DataSource =
MB> objDS.Tables["tblOrganisation"].DefaultView;
MB> switch (objDS.Tables["tblOrganisation"].Rows["Level"].ToString())
MB> {
MB> case "1": this.rdbtlstLevel.Items[0].Selected =
true;
MB> break;
MB> case "2":
MB> this.rdbtlstLevel.Items[1].Selected = true;
MB> break;
MB> case "3":
MB> this.rdbtlstLevel.Items[2].Selected = true;
MB> break;
MB> }
MB> this.rpUser.DataBind();
MB> ...
MB> Hence what I wan't to do is to get the values 1,2,3 from access,
MB> transform them to either true or false and then set The correct
MB> ListItem to checked on the *.aspx form for each user.
MB> MB> Any hint from someone??
MB> MB> //Michael
MB> ---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche

Hi Michael
You're correct, now everything works great. Thanks!

//Michael
Mar 9 '06 #3

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

Similar topics

9
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
1
by: Jonathan | last post by:
I am getting an error message that other people have gotten. I have done some search and reading enough to see that this error isn't only happening to me. However, I am not able to discern a...
2
by: Suresh.P.R | last post by:
Hi, While using the RadioButtonList control, that I populated in the runtime, I am not able to get the selected item in the javascript while referring document.Form.RadioButtonList.value. ...
0
by: Ryan Taylor | last post by:
Hello. I am having another issue. I need to execute some JavaScript whenever a radio button is clicked. I am currently using a RadioButtonList control to generate the radio buttons because of...
1
by: Stephen Noronha | last post by:
Hi, If I have a radiobuttonlist control and have some items in them, is it possible to hide one item depending on "situation" for eg: Users, Managers log in and see the same radiobuttonlist...
0
by: djarmoluk | last post by:
I have a RadioButtonList (named rbAnswers) control within a repeater control. When binding to the repeater, I am trying to add an "OnChange" attribute to the individual list item controls (input...
1
by: annbb | last post by:
I have a piece of code which resets all the control on a form ..but if I also put an option group on the form and the relevant code in the routine to reset it I get an error message saying that...
1
by: ravindravarman | last post by:
I need to assing some value from the java script variable in the .aspx page to a server side variable in the .aspx.cs page. Can any one help me with this? Thanks, Ravi
1
by: semomaniz | last post by:
I have a panel set up in a webpage and inside that panel i have various labels and textboxes setup. I am trying to assign a value to the label when the page loads. panel is named cpanel and a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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.