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. How to get the select value in a multiple dropdownlist

How to get the select value in a multiple dropdownlist

Scheduled Pinned Locked Moved C#
helptutorial
3 Posts 3 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.
  • V Offline
    V Offline
    vanilsonwdd
    wrote on last edited by
    #1

    hi, I'm trying to get multiple values that was selected in a dropdown list, the problem is that it's only returning one value, if I select two or more values only give me one, here's the code:

    List dep = new List();
    foreach (ListItem item in sltnamedep.Items)
    {

            if (item.Selected)
            {
    
    
                
                dep.Add(item.Text);
    
    
            }
    
        }
        for (int i = 0; i < dep.Count; i++)
            Response.Write(dep\[i\]);
    
    J M 2 Replies Last reply
    0
    • V vanilsonwdd

      hi, I'm trying to get multiple values that was selected in a dropdown list, the problem is that it's only returning one value, if I select two or more values only give me one, here's the code:

      List dep = new List();
      foreach (ListItem item in sltnamedep.Items)
      {

              if (item.Selected)
              {
      
      
                  
                  dep.Add(item.Text);
      
      
              }
      
          }
          for (int i = 0; i < dep.Count; i++)
              Response.Write(dep\[i\]);
      
      J Offline
      J Offline
      Jibesh
      wrote on last edited by
      #2

      is the MultiSelection is enabled for the listView? can you print/check the number of selected items using sltnamedep.Items.Count property

      Jibesh V P

      1 Reply Last reply
      0
      • V vanilsonwdd

        hi, I'm trying to get multiple values that was selected in a dropdown list, the problem is that it's only returning one value, if I select two or more values only give me one, here's the code:

        List dep = new List();
        foreach (ListItem item in sltnamedep.Items)
        {

                if (item.Selected)
                {
        
        
                    
                    dep.Add(item.Text);
        
        
                }
        
            }
            for (int i = 0; i < dep.Count; i++)
                Response.Write(dep\[i\]);
        
        M Offline
        M Offline
        micke andersson
        wrote on last edited by
        #3

        Make sure you have focus on the control. MSDN says:

        Quote:

        Items appear selected only when the ListView control has focus. To select items in response to a user action such as a button click, be sure to call the Focus method in addition to setting this property.

        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