Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Disaplying different panels from options in a dropdown list

Disaplying different panels from options in a dropdown list

Scheduled Pinned Locked Moved C#
csharpasp-nettutorial
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AdamskiR
    wrote on last edited by
    #1

    Hi I have a number of options which i want to when clicked open up a panel below with another dropdown list relating to the origional choice. Each option from the first drop down list would open a new panel with a new dropdown list and remove the previous. Any ideas how to code something like this, im guessing its easier than I am trying to work it out! This is for c# asp.net Thanks Adam :)

    X 1 Reply Last reply
    0
    • A AdamskiR

      Hi I have a number of options which i want to when clicked open up a panel below with another dropdown list relating to the origional choice. Each option from the first drop down list would open a new panel with a new dropdown list and remove the previous. Any ideas how to code something like this, im guessing its easier than I am trying to work it out! This is for c# asp.net Thanks Adam :)

      X Offline
      X Offline
      XRaheemX
      wrote on last edited by
      #2

      If you're trying to make a static form that doesn't change then what you're doing is easy as pie: Create your form with all of the drop downs in their own seperate "Panel" controls. (Use a Table for the proper line ups of drop downs). Then simply change the Visible property of all of the drop downs to false (except for the original one). Now make sure the "AutoPostBack" is set to true on the first dropdownlist. Then in the "OnSelectionChanged" (or something like that) event, simple check the value of the new dropdownlist selected item and make the corresponding panel control visible according to the selection. Now if you're using BOUND data, this is all a different story that I'm not going to type up unless this is the case :laugh:

      A 1 Reply Last reply
      0
      • X XRaheemX

        If you're trying to make a static form that doesn't change then what you're doing is easy as pie: Create your form with all of the drop downs in their own seperate "Panel" controls. (Use a Table for the proper line ups of drop downs). Then simply change the Visible property of all of the drop downs to false (except for the original one). Now make sure the "AutoPostBack" is set to true on the first dropdownlist. Then in the "OnSelectionChanged" (or something like that) event, simple check the value of the new dropdownlist selected item and make the corresponding panel control visible according to the selection. Now if you're using BOUND data, this is all a different story that I'm not going to type up unless this is the case :laugh:

        A Offline
        A Offline
        AdamskiR
        wrote on last edited by
        #3

        Thanks for the quick reply. The options in the drop downs are manually put in, not taken from a database due to them maybe changing quite regularly. However there may be 3 options selected which will cause a other funtion to run, but i think i know how to get round that one.....:| I have the panels ready etc, the first drop down needs to be a required option which i dont have a problem with, but its where i need to add the other code im having the problem with?:confused::sigh: Thanks Adam:)

        X 1 Reply Last reply
        0
        • A AdamskiR

          Thanks for the quick reply. The options in the drop downs are manually put in, not taken from a database due to them maybe changing quite regularly. However there may be 3 options selected which will cause a other funtion to run, but i think i know how to get round that one.....:| I have the panels ready etc, the first drop down needs to be a required option which i dont have a problem with, but its where i need to add the other code im having the problem with?:confused::sigh: Thanks Adam:)

          X Offline
          X Offline
          XRaheemX
          wrote on last edited by
          #4

          By "the other code" I assume you mean the code to make the other panels visible? If so: In the GUI, select the main dropdownlist. In the "events" section of the properties list doulbe click the empty space to the right of the event: "SelectedIndexChanged" You code will go in here. If you'll paste the code you currently have, I can show you what I mean. Or hit me up on MSN @ xraheemx@hotmail.com

          A 1 Reply Last reply
          0
          • X XRaheemX

            By "the other code" I assume you mean the code to make the other panels visible? If so: In the GUI, select the main dropdownlist. In the "events" section of the properties list doulbe click the empty space to the right of the event: "SelectedIndexChanged" You code will go in here. If you'll paste the code you currently have, I can show you what I mean. Or hit me up on MSN @ xraheemx@hotmail.com

            A Offline
            A Offline
            AdamskiR
            wrote on last edited by
            #5

            Unfotunatley we cant use msn at work:doh: So ill have to put it here. What ive got is the first part so that if it is anything but the initial value it will do the panel viewing:

            private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
            {
            if (Speciality.SelectedItem.Value!="Select a speciality")
            {
            }
            }

            So as an example of the options: Select a speciality Option 1 Option 2 Option 3 Option 4 Option 5 Thanks again for your help. Adam

            X 1 Reply Last reply
            0
            • A AdamskiR

              Unfotunatley we cant use msn at work:doh: So ill have to put it here. What ive got is the first part so that if it is anything but the initial value it will do the panel viewing:

              private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
              {
              if (Speciality.SelectedItem.Value!="Select a speciality")
              {
              }
              }

              So as an example of the options: Select a speciality Option 1 Option 2 Option 3 Option 4 Option 5 Thanks again for your help. Adam

              X Offline
              X Offline
              XRaheemX
              wrote on last edited by
              #6

              OK, so lets say that the other dropdowns are named option1, option2, option3 etc. The following code will work for you:

              private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
              {
                  select(Speciality.SelectedItem.Value.ToLower())
                  {
                       case "option 1":
                         option1.Visible = true;
                         break;
                       
                       case "option 2":
                         option2.Visible = true;
                         break;
              
                       case "option 3":
                         option3.Visible = true; 
                          break;
              
                       case "option 4":
                          option4.Visible = true;
                          break;
              
                       case "option 5":
                          option5.Visible = true;
                          break;
              
                       default:
                          //In case you want to do something "else"
                          break;
                  }
              }
              
              X A 2 Replies Last reply
              0
              • X XRaheemX

                OK, so lets say that the other dropdowns are named option1, option2, option3 etc. The following code will work for you:

                private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
                {
                    select(Speciality.SelectedItem.Value.ToLower())
                    {
                         case "option 1":
                           option1.Visible = true;
                           break;
                         
                         case "option 2":
                           option2.Visible = true;
                           break;
                
                         case "option 3":
                           option3.Visible = true; 
                            break;
                
                         case "option 4":
                            option4.Visible = true;
                            break;
                
                         case "option 5":
                            option5.Visible = true;
                            break;
                
                         default:
                            //In case you want to do something "else"
                            break;
                    }
                }
                
                X Offline
                X Offline
                XRaheemX
                wrote on last edited by
                #7

                Keep in mind that if all of this is static, it would be better (and MUCH faster) to do this in Javascript so the items would not have to PostBack (and page flicker) in order to update the visibility of the dropdowns.

                1 Reply Last reply
                0
                • X XRaheemX

                  OK, so lets say that the other dropdowns are named option1, option2, option3 etc. The following code will work for you:

                  private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
                  {
                      select(Speciality.SelectedItem.Value.ToLower())
                      {
                           case "option 1":
                             option1.Visible = true;
                             break;
                           
                           case "option 2":
                             option2.Visible = true;
                             break;
                  
                           case "option 3":
                             option3.Visible = true; 
                              break;
                  
                           case "option 4":
                              option4.Visible = true;
                              break;
                  
                           case "option 5":
                              option5.Visible = true;
                              break;
                  
                           default:
                              //In case you want to do something "else"
                              break;
                      }
                  }
                  
                  A Offline
                  A Offline
                  AdamskiR
                  wrote on last edited by
                  #8

                  Its not allowing me to build the project with code like this? Im getting all sorts of build errors for missing ; and for the case text? Thanks Adam

                  X 1 Reply Last reply
                  0
                  • A AdamskiR

                    Its not allowing me to build the project with code like this? Im getting all sorts of build errors for missing ; and for the case text? Thanks Adam

                    X Offline
                    X Offline
                    XRaheemX
                    wrote on last edited by
                    #9

                    The code that I wrote is not the actual code you should use, just an example of how to do it. Paste all of your code here and I'll fix your syntax for you.

                    X 1 Reply Last reply
                    0
                    • X XRaheemX

                      The code that I wrote is not the actual code you should use, just an example of how to do it. Paste all of your code here and I'll fix your syntax for you.

                      X Offline
                      X Offline
                      XRaheemX
                      wrote on last edited by
                      #10

                      Although syntactically my code is correct, are you sure you are using a c# code behind and not a VB.NET code behind? Also, did you paste exactly what I wrote?

                      A 1 Reply Last reply
                      0
                      • X XRaheemX

                        Although syntactically my code is correct, are you sure you are using a c# code behind and not a VB.NET code behind? Also, did you paste exactly what I wrote?

                        A Offline
                        A Offline
                        AdamskiR
                        wrote on last edited by
                        #11

                        Yes, im positive it is a c# code behind page. I pasted exactly what you wrote in, but just changed the case values and visible panel names to that of what I am using. I have underlined where I am getting build errors

                        private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
                        		{	
                        			select(Speciality.SelectedItem.Value.ToLower()) 			
                                                {
                        				case "Breast Surgery": 
                        			 SpecialityBreastSurgery.Visible = true;
                        			 break;
                                 
                        				case "Cardiology": 
                        			SpecialityCardiology.Visible = true;
                        			break;
                        
                        				default:				//In case you want to do something "else"
                        				break;
                        			}
                        		}
                        

                        Many thanks Adam

                        X 1 Reply Last reply
                        0
                        • A AdamskiR

                          Yes, im positive it is a c# code behind page. I pasted exactly what you wrote in, but just changed the case values and visible panel names to that of what I am using. I have underlined where I am getting build errors

                          private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
                          		{	
                          			select(Speciality.SelectedItem.Value.ToLower()) 			
                                                  {
                          				case "Breast Surgery": 
                          			 SpecialityBreastSurgery.Visible = true;
                          			 break;
                                   
                          				case "Cardiology": 
                          			SpecialityCardiology.Visible = true;
                          			break;
                          
                          				default:				//In case you want to do something "else"
                          				break;
                          			}
                          		}
                          

                          Many thanks Adam

                          X Offline
                          X Offline
                          XRaheemX
                          wrote on last edited by
                          #12

                          omg I'm so sorry... my mind was in VB.NET when I wrote this. (VB uses the keywork SELECT instead of SWITCH that is used in C#"

                          private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
                          {
                              switch(Speciality.SelectedItem.Value.ToLower())
                              {
                                  case "breast surgery":
                                     SpecialityBreastSurgery.Visible = true;
                                     break;
                          
                                  case "cardiology":
                          	   SpecialityCardiology.Visible = true;
                                     break;
                          
                          	default: //In case you want to do something "else"
                                  break;
                              }
                          }
                          

                          Also remember that your strings for your CASE statements MUST be all lowercase in this instance because I used a .ToLower() in the switch. (I have a habit of doing this to remove casing errors). If you want to use exact case, just simply remove the .ToLower() from the switch.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups