Radio Control Problem (again)

A

Angela

Hi

I got some help off this forum a couple of days ago but was still not
able to solve the problem.

I want to use the following controls for radio buttons so that I can
put each button into a TD cell:

<td>
<asp:RadioButton id="RadioButton1" groupname="Name" value="1"
runat="server" />
</td>
<td>
<asp:RadioButton id="Radiobutton2" groupname="Name" value="2"
runat="server" />
</td>

I know 'value' isn't a known attribute of a radio control but that's
the only way I could access the numerical values 1 and 2
(Request.Form("Name"))

Question: Is it possible to select the correct radioButton when the
page is loaded, and if so what is the code for this? e.g. if a value
of 2 comes back from the DB check Radiobutton2

Thanks in advance
 
D

DujHoD

Why are you using Request.Form? Why not just use code like this in
your codebehind?

if (RadioButton1.Checked)
// The user selected RadioButton1.
else if (Radiobutton2.Checked)
// The user selected RadioButton2.

Similarly, you can set the Checked property of the RadioButtons as
soon as you get your data from the database in the codebehind.

bool myBoolean = myDataReader.GetBoolean(0);
RadioButton1.Checked = myBoolean;
Radiobutton2.Checked = !myBoolean;
 
A

Angela

Thanks for the reply,

I guess I will have to use that method, it's just I have loads of radio
buttons to cycle through!

RadioButton1 - RadioButton10
 
D

DujHoD

You could put them all in an array, making programmatic access easier.
(If you wanted to get really fancy, you could even create a new
control inheriting from RadioButtonList and make it do exactly what
you want.)
 

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

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top