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

multiple elements conditional on if

Hi

I am trying to set some elements to values depending on the selection in a
test box. The first possible value that can be selected should set
fmttest1= "", fmttest2=" to " and fmttest3="". The second value that can be
selected from the test box should set the fmttest1 ="From ", fmttest2=" to
", fmttest3=" less than".

here is what i have so far but i cannot get an if statement to apply the
condition to more than one item.

private void lbSelect_SelectedIndexChanged(object sender, System.EventArgs
e)
{
if (lbSelect.SelectedIndex=0)
(fmttext1="" fmttext2=" to " fmttest3="");
else if ((lbSelect.SelectedIndex=1)
(fmttext1="From " fmttext2=" to " fmttext3=" less than ");
}
} }

I know this syntax is wrong - but what is the correct way to use many
elements in an if statement - should i use a select or case statement?

thanks

Doug
Jun 22 '06 #1
1 1308
gordon wrote:
I am trying to set some elements to values depending on the selection in a
test box. The first possible value that can be selected should set
fmttest1= "", fmttest2=" to " and fmttest3="". The second value that can be
selected from the test box should set the fmttest1 ="From ", fmttest2=" to
", fmttest3=" less than".

here is what i have so far but i cannot get an if statement to apply the
condition to more than one item.

private void lbSelect_SelectedIndexChanged(object sender, System.EventArgs
e)
{
if (lbSelect.SelectedIndex=0)
(fmttext1="" fmttext2=" to " fmttest3="");
else if ((lbSelect.SelectedIndex=1)
(fmttext1="From " fmttext2=" to " fmttext3=" less than ");
}
} }

I know this syntax is wrong - but what is the correct way to use many
elements in an if statement - should i use a select or case statement?


Well, you certainly *could* do it with a switch:

switch (lbSelect.SelectedIndex)
{
case 0:
fmttext1="";
fmttext2=" to ";
fmttext3="";
break;
case 1:
fmttext1="From ";
fmttext2=" to ";
fmttext3=" less than ";
break;
}

Personally I'd probably go with if/else until I had more than two
cases, at which point I'd go to the switch statement - or have:

static readonly string[,] TextStrings = { {"", " to ", ""}, {"From ", "
to ", " less than "} };

and do it in one hit so long as the value of SelectedIndex is in the
appropriate range. That would involve less code duplication.

Jon

Jun 22 '06 #2

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

Similar topics

27
by: Simon Templar | last post by:
Hi, I am trying to introduce a multiple datepicker into a webpage and the problem arises with the second picker. I tried to copy and adapt the code I employed for the first one, renaming the...
12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
1
by: Spartanicus | last post by:
I'm pondering what the various drawbacks are of the methods to code UI elements who's function relies on javascript and css. Currently on http://www.pan-europe.utvinternet.ie/ I use styled <a>...
2
by: John Kreps | last post by:
(acc 2002) I've got six unbound text boxes on a subform that has a white background. Each of those six boxes has an expression that when true, will change its background from white to another...
1
by: ammarton | last post by:
Hello all...I'm a bit new to working with Macros in Access so forgive me if the terminology I use is not accurate. To preface this, basically I am using a form on a replicated database so the...
2
by: Piper707 | last post by:
Hi, I need to know if there is any way of achieving conditional processing for XSD elements. --------------------------------------------------------------- <criteria></criteria> = a complex...
2
by: dinkle | last post by:
Hi Y'all, I am pretty new to js and am hitting a few snags. I need to process a multiple select list and pass it onto a PHP script. I can only get the first value in the JS and have no idea how...
5
by: Neil | last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com... Question for you. I'm doing something similar, only, instead of opening...
2
by: helplakshmi | last post by:
Hi All, I am new to php. The form that i am designing has few input input fields with submit and reset button. The functionality of submit and reset are working properly till now. My form ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.