[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Multiple condition on SelectedIndexChange

Hello Experts,
On my webform, i have a series of dropdown controls(DDL1, DDL2 & DDL3). DDL1 has list (value) items from 1-10 while DDL2 and DDL3 are just either 'Yes' or 'No' .

What i wanted to happen is that if user chooses between 1-6 then...
1.0       DDL2 will be inactive or disabled and value='No' on postback
2.0       DDL3 will be inactive or disabled and value 'No' on postback

And if user chooses between 7-10 then...
1.0       DDL2 will be active or enabled on postback
2.0       DDL3 will be active or enabled on postback

My code is pretty obvious had some syntax problem but have wasted time trying to fix it and figuring out how to populate DDL2 based on condition 1.
Any help is much appreciated.
protected void DDL1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if   (String.Compare(DDL1.SelectedValue, "01", true) == 0)
	       (String.Compare(DDL1.SelectedValue, "02", true) == 0)
	       (String.Compare(DDL1.SelectedValue, "03", true) == 0)
	       (String.Compare(DDL1.SelectedValue, "04", true) == 0)
	       (String.Compare(DDL1.SelectedValue, "05", true) == 0)
	       (String.Compare(DDL1.SelectedValue, "06", true) == 0)
        {
            DDL2.Enabled = false;
            DDL3.Enabled = false;

        }
        else
        {
            DDL2.Enabled = true;
            DDL3.Enabled = true;

        }
    }

Open in new window

0
jsuanque
Asked:
jsuanque
  • 5
  • 3
1 Solution
 
magicdlfCommented:
Is this what you want?
        protected void DDL1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((String.Compare(DDL1.SelectedValue, "01", true) == 0) ||
               (String.Compare(DDL1.SelectedValue, "02", true) == 0) ||
               (String.Compare(DDL1.SelectedValue, "03", true) == 0) ||
               (String.Compare(DDL1.SelectedValue, "04", true) == 0) ||
               (String.Compare(DDL1.SelectedValue, "05", true) == 0) ||
               (String.Compare(DDL1.SelectedValue, "06", true) == 0))
            {
                DDL2.Enabled = false;
                DDL3.Enabled = false;

            }
            else
            {
                DDL2.Enabled = true;
                DDL3.Enabled = true;

            }
        }
0
 
jsuanqueAuthor Commented:
Hello Maqicdlf,
Almost, except for the other item...i mean assigning a value of 'No' on this case...
If a user chooses between 1-6 then...
1.0       DDL2 will be inactive or disabled and value='No' on postback
2.0       DDL3 will be inactive or disabled and value 'No' on postback
0
 
magicdlfCommented:
Assume you always put "Yes" before "No" in DDL2 and DDL3:
            if ((String.Compare(DDL1.SelectedValue, "01", true) == 0) ||
               (String.Compare(DDL1.SelectedValue, "02", true) == 0) ||
               (String.Compare(DDL1.SelectedValue, "03", true) == 0) ||
               (String.Compare(DDL1.SelectedValue, "04", true) == 0) ||
               (String.Compare(DDL1.SelectedValue, "05", true) == 0) ||
               (String.Compare(DDL1.SelectedValue, "06", true) == 0))
            {
                DDL2.Enabled = false;
                DDL3.Enabled = false;
                DDL2.SelectedIndex = 1; // DDL2.SelectedIndex = 0;  
                DDL3.SelectedIndex = 1; // DDL3.SelectedIndex = 0;  

            }
            else
            {
                DDL2.Enabled = true;
                DDL3.Enabled = true;

            }
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jsuanqueAuthor Commented:
Oh by the way, got errors on suggested code..

"Method name expected"
0
 
magicdlfCommented:
Which line?
0
 
jsuanqueAuthor Commented:
Sorry i missed the double pipe "||"...
0
 
jsuanqueAuthor Commented:
Got it ...Thanks heaps.
0
 
jsuanqueAuthor Commented:
Thanks heaps...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now