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

jsuanqueAsked:
Who is Participating?
 
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
 
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.