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. Web Development
  3. ASP.NET
  4. ListBox Not Functioning.....Multiple Selection

ListBox Not Functioning.....Multiple Selection

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelp
4 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.
  • C Offline
    C Offline
    codingrocks
    wrote on last edited by
    #1

    I am doing an application in ASP .NET in which i am using a list box with multiple selection. I am using a sqldatasource to bind values to the list box. Everything works fine till this. i want the page to send the selected multiple values in list box to be in two different text boxes i tried this code and working, all the selected values comes to single text boxes. I want first selected value to be in textbox1 and second value to be in textbox2.. This is the code... On Click event of a button

        int i;
    
        txt\_uname1.Text = "selected" + " ";
        
        for (i = 0; i < list\_users.Items.Count - 1; i++)
        {
            if (list\_users.Items\[i\].Selected)
            {
                //txt\_uname1.Text = list\_users.Items\[i\].Text;
    
                txt\_uname1.Text = txt\_uname1.Text + list\_users.Items\[i\].Text + " ";                   
            }
            
        }
    

    Please help me fixing this... Thanks in advance

    SAJAN A PILLAI ASP.NET,C#.NET Programmer BANGALORE "Winners don't do different things. They do things differently. ...

    S C 2 Replies Last reply
    0
    • C codingrocks

      I am doing an application in ASP .NET in which i am using a list box with multiple selection. I am using a sqldatasource to bind values to the list box. Everything works fine till this. i want the page to send the selected multiple values in list box to be in two different text boxes i tried this code and working, all the selected values comes to single text boxes. I want first selected value to be in textbox1 and second value to be in textbox2.. This is the code... On Click event of a button

          int i;
      
          txt\_uname1.Text = "selected" + " ";
          
          for (i = 0; i < list\_users.Items.Count - 1; i++)
          {
              if (list\_users.Items\[i\].Selected)
              {
                  //txt\_uname1.Text = list\_users.Items\[i\].Text;
      
                  txt\_uname1.Text = txt\_uname1.Text + list\_users.Items\[i\].Text + " ";                   
              }
              
          }
      

      Please help me fixing this... Thanks in advance

      SAJAN A PILLAI ASP.NET,C#.NET Programmer BANGALORE "Winners don't do different things. They do things differently. ...

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      What if user selects more than 3 items from the ListBox ? Where are you going to show those items ? Code modification for your logic (Not tested) int i; txt_uname1.Text = "selected" + " "; bool isFirstSelected for (i = 0; i < list_users.Items.Count - 1; i++) { if (list_users.Items[i].Selected) { if(!isFirstSelected) { //TextBox 1 txt_uname1.Text = list_users.Items[i].Text; isFirstSelected=true; } else { //Text Box 2 txt_uname2.Text = list_users.Items[i].Text; break; } }

      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

      C 1 Reply Last reply
      0
      • C codingrocks

        I am doing an application in ASP .NET in which i am using a list box with multiple selection. I am using a sqldatasource to bind values to the list box. Everything works fine till this. i want the page to send the selected multiple values in list box to be in two different text boxes i tried this code and working, all the selected values comes to single text boxes. I want first selected value to be in textbox1 and second value to be in textbox2.. This is the code... On Click event of a button

            int i;
        
            txt\_uname1.Text = "selected" + " ";
            
            for (i = 0; i < list\_users.Items.Count - 1; i++)
            {
                if (list\_users.Items\[i\].Selected)
                {
                    //txt\_uname1.Text = list\_users.Items\[i\].Text;
        
                    txt\_uname1.Text = txt\_uname1.Text + list\_users.Items\[i\].Text + " ";                   
                }
                
            }
        

        Please help me fixing this... Thanks in advance

        SAJAN A PILLAI ASP.NET,C#.NET Programmer BANGALORE "Winners don't do different things. They do things differently. ...

        C Offline
        C Offline
        chandralekha
        wrote on last edited by
        #3

        For that instead of assigning values directly to textbox,first you store values to a string array.And after that you create other loop and assign values to your textboxes. Hope this will help you

        1 Reply Last reply
        0
        • S Sandeep Akhare

          What if user selects more than 3 items from the ListBox ? Where are you going to show those items ? Code modification for your logic (Not tested) int i; txt_uname1.Text = "selected" + " "; bool isFirstSelected for (i = 0; i < list_users.Items.Count - 1; i++) { if (list_users.Items[i].Selected) { if(!isFirstSelected) { //TextBox 1 txt_uname1.Text = list_users.Items[i].Text; isFirstSelected=true; } else { //Text Box 2 txt_uname2.Text = list_users.Items[i].Text; break; } }

          Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

          C Offline
          C Offline
          codingrocks
          wrote on last edited by
          #4

          Thanks for the reply....It works.

          SAJAN A PILLAI ASP.NET,C#.NET Programmer BANGALORE "Winners don't do different things. They do things differently. ...

          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