Assign database value to a RadioButtonList control

M

Michael Bohman

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
 
M

Michael Nemtsev

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
 
M

Michael Bohman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top