Formatting Radios

A

Angela

Hi everyone,

At the moment I am using the syntax of:

<asp:radiobuttonlist id="rdDrive" runat="server" RepeatLayout="Table"
RepeatColumns="2">
<asp:ListItem Value="1" text="Yes"></asp:ListItem>
<asp:ListItem Value="0" text="No"></asp:ListItem>

</asp:radiobuttonlist>

But what I prefer to do to give me greater layout flexibility is have
one radio in one <TD> cell and another in another <TD> cell. So headers
can be added above the corresponding radio buttons (instead of the side
of the radio).

I know I can use:

<asp:RadioButton id="radio1" groupname="Drive" runat="server" />

<asp:RadioButton id="radio2" groupname="Drive" runat="server" />

but when it comes to requesting the value of the "Drive" group is there
a neat way to loop round the Drive group and find the selected value? (I
may have many radios in the Drive group and don't want to request each
an every radio to see if it is selected.)
 
K

Kevin Spencer

Request.Form("Drive") would do it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
A

Angela

thanks for the reply, didn't think of that!

but it will only return the name of the radio not the value (as I think
you can't assign values to asp:radio can you??)

also how would you select the correct radio if you were to revisit the
page?

at the moment I am using syntax like this:
rdDrive.SelectedIndex =
rdDrive.Items.IndexOf(rdDrive.Items.FindByValue(myPersonality.Drive))

how would you do this with a group?
 
K

Kevin Spencer

but it will only return the name of the radio not the value (as I think
you can't assign values to asp:radio can you??)

It will return the value of the selected radio button in that group. The
name of the group is "Drive".
also how would you select the correct radio if you were to revisit the
page?

Depends on how you define "the correct radio" and "revisit the page."
how would you do this with a group?

Do you mean a RadioButtonGroup? I thought we were talking about individual
RadioButtons.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
A

Angela

Sorry I wasn't making myself clear (friday slump)

OK, I have a page that is an add and edit page.

Once the data is submitted and the user wants to edit the data, the
radios will have to be pre selected according to values they previously
submitted.

So say I have radios:

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

and the value I get back from DB is 1, how would I get it to pre select
the correct radio button from the group "Drive" when the page is loaded?
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top