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

switch that uses radio button selection

For an exercise, I must use a switch statement to assign values to
variables based on the 1 or 4 radio buttons selected. Can I do this
without using an extra if-else statement? Some code below:

if (makeOverRadioButton.Checked) {intServiceChoiceLocal = 1;}
else if (hairStylingRadioButton.Checked) {intServiceChoiceLocal = 2;}
else if (manicureRadioButton.Checked) {intServiceChoiceLocal = 3;}
else if (permanentMakeupRadioButton.Checked) {intServiceChoiceLocal
=4;}

switch (intServiceChoiceLocal)
{
case 1:
strServiceNameLocal = "Make Over";
decServiceCostLocal = decMAKEOVER_PRICE;
break;

(code snip, etc.)

-
http://mysite.verizon.net/vze8adrh/news.html (profile) --Tim923 My email is valid.
Nov 16 '05 #1
3 8968
>variables based on the 1 or 4 radio buttons selected. Can I do this

I meant: 1 OF 4

I find those concise if-else statements easier to follow, but will
have to change them back to please the prof.

-
http://mysite.verizon.net/vze8adrh/news.html (profile) --Tim923 My email is valid.
Nov 16 '05 #2
Hi Tim,

You can put the radiobuttons in groupbox and use it like this :)
for (int i = 0; i < groupBox1.Controls.Count; i ++)
{
RadioButton current = (RadioButton)groupBox1.Controls[i] ;

switch (current.Checked)
{
case true:
// your code here
break;
}
}

Regards,
Peter Jausovec
(http://blog.jausovec.net)

Tim923" <ju********@verizon.net> je napisal v sporocilo
news:ub********************************@4ax.com ...
variables based on the 1 or 4 radio buttons selected. Can I do this


I meant: 1 OF 4

I find those concise if-else statements easier to follow, but will
have to change them back to please the prof.

-
http://mysite.verizon.net/vze8adrh/news.html (profile) --Tim923 My email
is valid.

Nov 16 '05 #3
Use standard HTML (non Server control) radiobuttons (<input type="radio"
.....>)

Assigned each the same ID and provide VALUE attributes (1,2,3,4)
<input type="Radio" id="Hair" Value="1">Make Over</input> etc

Read the value of that ID from the Request.Form collection.
int choice = Convert.ToInt32(Request.Form["Hair"]);

Use those values as the cases of the switch.
Presumably there is a way to to this use a server control, but I do see
it.

--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"Tim923" <ju********@verizon.net> wrote in message
news:5s********************************@4ax.com...
For an exercise, I must use a switch statement to assign values to
variables based on the 1 or 4 radio buttons selected. Can I do this
without using an extra if-else statement? Some code below:

if (makeOverRadioButton.Checked) {intServiceChoiceLocal = 1;}
else if (hairStylingRadioButton.Checked) {intServiceChoiceLocal = 2;}
else if (manicureRadioButton.Checked) {intServiceChoiceLocal = 3;}
else if (permanentMakeupRadioButton.Checked) {intServiceChoiceLocal
=4;}

switch (intServiceChoiceLocal)
{
case 1:
strServiceNameLocal = "Make Over";
decServiceCostLocal = decMAKEOVER_PRICE;
break;

(code snip, etc.)

-
http://mysite.verizon.net/vze8adrh/news.html (profile) --Tim923 My email

is valid.
Nov 16 '05 #4

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

Similar topics

1
by: Francisco Mendez | last post by:
I have the following problem: When i use "scooters" in the value of the radio as well as in the switch statement, the code doesn't get executed, but if i use "scooter" it does. Is there...
10
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
2
by: jason | last post by:
The following (likely far from imperfect code), reports a value of NaN in the j4 display. I suppose the problem is I am not really passing the "checked" value of the radio button via .value ......
6
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked ...
2
by: Stoic | last post by:
I'm offering a selection of three items. One is $25, the second is $50, the third is $100. Along with selection one of the items I need to pass the quantity of the selection. Here is the code now....
9
by: mantrid | last post by:
hello In the function below radtext is an array of 3 radio buttons with values set to 1, 2 and 3. but variables starty and finishy are not returned. ...
1
by: Para | last post by:
Hi , I am working on a project using C/C++ in linux environment. Our program right now using the command line(console window) inputs and starts executing. command on console are to start...
3
by: Chris Marsh | last post by:
Hello, Is it possible w/ASP.Net to set the property of the radio button control to 'read-only' after the user has made their selection before hitting an 'submit' button? Think of a multiple...
10
by: mukeshrasm | last post by:
Hi I have a html in which there is two selection box and two radio button. Radio buttion is of array type. What I want if user will click the radio button then only he/she be able to make...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.