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. Problem with ListBox

Problem with ListBox

Scheduled Pinned Locked Moved ASP.NET
16 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 Vimalsoft Pty Ltd

    Good Day All I have a Listbox with name lstbxTags and it get populated fine and i have another two List boxes named ListBox1 and lstbxLecturers in lstbxTags_SelectedIndexChanged event of the Listbox lstbxTags i have the Following Code

    protected void lstbxTags_SelectedIndexChanged(object sender, EventArgs e)
    {
    //This Session Variable will Hold the ID of the selected Staff

        BLL.BLL obj = new BLL.BLL();
    
        DataSet ds = new DataSet();
    
        String SelectedStaff = Convert.ToString(lstbxTags.SelectedItem.Value);
    
        //Assign the returned id to the Session variable 
        int Selected\_Staff = obj.Get\_Selected\_id\_of\_Tag(SelectedStaff, Convert.ToString(Session\["ActiveDatabase"\]));
    
        ds = obj.FILTER\_TAG(Selected\_Staff, Convert.ToString(Session\["ActiveDatabase"\]));
    
        //Binding the Listboxes
    
        ListBox1.DataSource = ds;
     
        ListBox1.DataTextField = "Descr";
    
        ListBox1.Visible = true;
    
        lstbxLecturers.Visible = false;
    
        ListBox1.DataBind();          
    
        
    }
    

    Now when i select something in the lstbxTags, nothing gets Populated in ListBox1, i have step through the code and it goes without a Problem. what is the Problem Thanks

    Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

    M Offline
    M Offline
    monu nair
    wrote on last edited by
    #2

    what is your Requirement.

    Mahendra Bisht.

    V 2 Replies Last reply
    0
    • M monu nair

      what is your Requirement.

      Mahendra Bisht.

      V Offline
      V Offline
      Vimalsoft Pty Ltd
      wrote on last edited by
      #3

      My Problem is that the Listbox1 does not Get Populated with the values when you select an Item in lstbxTags listbox

      Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

      1 Reply Last reply
      0
      • M monu nair

        what is your Requirement.

        Mahendra Bisht.

        V Offline
        V Offline
        Vimalsoft Pty Ltd
        wrote on last edited by
        #4

        I even Added the Following Code at the End

        //Binding the Listboxes
        if (ds.Tables[0].Rows.Count > 0)
        {

                ListBox1.DataSource = ds;
        
                ListBox1.DataTextField = "Descr";
        
                ListBox1.Visible = true;
        
                lstbxLecturers.Visible = false;
        
                ListBox1.DataBind();
            }
            else
            {
        
                //Leave it there Way it is
                ListBox1.Visible = false;
        
                lstbxLecturers.Visible = true;
            }
        

        this is to test if there are any records returned and the First true to the If statement get executed. Thank you

        Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

        1 Reply Last reply
        0
        • V Vimalsoft Pty Ltd

          Good Day All I have a Listbox with name lstbxTags and it get populated fine and i have another two List boxes named ListBox1 and lstbxLecturers in lstbxTags_SelectedIndexChanged event of the Listbox lstbxTags i have the Following Code

          protected void lstbxTags_SelectedIndexChanged(object sender, EventArgs e)
          {
          //This Session Variable will Hold the ID of the selected Staff

              BLL.BLL obj = new BLL.BLL();
          
              DataSet ds = new DataSet();
          
              String SelectedStaff = Convert.ToString(lstbxTags.SelectedItem.Value);
          
              //Assign the returned id to the Session variable 
              int Selected\_Staff = obj.Get\_Selected\_id\_of\_Tag(SelectedStaff, Convert.ToString(Session\["ActiveDatabase"\]));
          
              ds = obj.FILTER\_TAG(Selected\_Staff, Convert.ToString(Session\["ActiveDatabase"\]));
          
              //Binding the Listboxes
          
              ListBox1.DataSource = ds;
           
              ListBox1.DataTextField = "Descr";
          
              ListBox1.Visible = true;
          
              lstbxLecturers.Visible = false;
          
              ListBox1.DataBind();          
          
              
          }
          

          Now when i select something in the lstbxTags, nothing gets Populated in ListBox1, i have step through the code and it goes without a Problem. what is the Problem Thanks

          Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #5

          Vuyiswa Maseko wrote:

          ds = obj.FILTER_TAG(Selected_Staff, Convert.ToString(Session["ActiveDatabase"])); //Binding the Listboxes ListBox1.DataSource = ds;

          Does Ds populating correctly?

          Vuyiswa Maseko wrote:

          ListBox1.DataTextField = "Descr";

          What about the data text field ? I have done a small prototype with ArrayList and bind the data, its working fine.

          cheers, Abhijit CodeProject MVP

          V 1 Reply Last reply
          0
          • A Abhijit Jana

            Vuyiswa Maseko wrote:

            ds = obj.FILTER_TAG(Selected_Staff, Convert.ToString(Session["ActiveDatabase"])); //Binding the Listboxes ListBox1.DataSource = ds;

            Does Ds populating correctly?

            Vuyiswa Maseko wrote:

            ListBox1.DataTextField = "Descr";

            What about the data text field ? I have done a small prototype with ArrayList and bind the data, its working fine.

            cheers, Abhijit CodeProject MVP

            V Offline
            V Offline
            Vimalsoft Pty Ltd
            wrote on last edited by
            #6

            This has been Working. So for the sake of look and feel , i too these controls and Put them in an Update Panel and Add them to a table, after i did that it stopped working. the "Descr" is Correct. as i said i tried to check if the returned Dataset has records by doing this

            //Binding the Listboxes
            if (ds.Tables[0].Rows.Count > 0)
            {

                    ListBox1.DataSource = ds;
            
                    ListBox1.DataTextField = "Descr";
            
                    ListBox1.Visible = true;
            
                    lstbxLecturers.Visible = false;
            
                    ListBox1.DataBind();
                }
                else
                {
            
                    //Leave it there Way it is
                    ListBox1.Visible = false;
            
                    lstbxLecturers.Visible = true;
                }
            

            And when i debug this , it says there are records, but i cant understand why dont they get populated in ListBox1 Thanks

            Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

            A 1 Reply Last reply
            0
            • V Vimalsoft Pty Ltd

              Good Day All I have a Listbox with name lstbxTags and it get populated fine and i have another two List boxes named ListBox1 and lstbxLecturers in lstbxTags_SelectedIndexChanged event of the Listbox lstbxTags i have the Following Code

              protected void lstbxTags_SelectedIndexChanged(object sender, EventArgs e)
              {
              //This Session Variable will Hold the ID of the selected Staff

                  BLL.BLL obj = new BLL.BLL();
              
                  DataSet ds = new DataSet();
              
                  String SelectedStaff = Convert.ToString(lstbxTags.SelectedItem.Value);
              
                  //Assign the returned id to the Session variable 
                  int Selected\_Staff = obj.Get\_Selected\_id\_of\_Tag(SelectedStaff, Convert.ToString(Session\["ActiveDatabase"\]));
              
                  ds = obj.FILTER\_TAG(Selected\_Staff, Convert.ToString(Session\["ActiveDatabase"\]));
              
                  //Binding the Listboxes
              
                  ListBox1.DataSource = ds;
               
                  ListBox1.DataTextField = "Descr";
              
                  ListBox1.Visible = true;
              
                  lstbxLecturers.Visible = false;
              
                  ListBox1.DataBind();          
              
                  
              }
              

              Now when i select something in the lstbxTags, nothing gets Populated in ListBox1, i have step through the code and it goes without a Problem. what is the Problem Thanks

              Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

              M Offline
              M Offline
              monu nair
              wrote on last edited by
              #7

              use the following line ListBox1.Items.Add(lstbxTags.SelectedItem);

              Mahendra Bisht.

              V 1 Reply Last reply
              0
              • M monu nair

                use the following line ListBox1.Items.Add(lstbxTags.SelectedItem);

                Mahendra Bisht.

                V Offline
                V Offline
                Vimalsoft Pty Ltd
                wrote on last edited by
                #8

                That will Work but in my case, after selecting a Value from the lstbxTags i got to the database and look for it ID , and from that , another SP is Called that will retrieve the Records based on that ID. So this is like a Filter thing. So a User will save a Filter tag with some records. Now i will be Displaying records based on that Filter Thank you

                Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

                M 1 Reply Last reply
                0
                • V Vimalsoft Pty Ltd

                  That will Work but in my case, after selecting a Value from the lstbxTags i got to the database and look for it ID , and from that , another SP is Called that will retrieve the Records based on that ID. So this is like a Filter thing. So a User will save a Filter tag with some records. Now i will be Displaying records based on that Filter Thank you

                  Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

                  M Offline
                  M Offline
                  monu nair
                  wrote on last edited by
                  #9

                  so your question solved now or not.

                  Mahendra Bisht.

                  V 1 Reply Last reply
                  0
                  • V Vimalsoft Pty Ltd

                    This has been Working. So for the sake of look and feel , i too these controls and Put them in an Update Panel and Add them to a table, after i did that it stopped working. the "Descr" is Correct. as i said i tried to check if the returned Dataset has records by doing this

                    //Binding the Listboxes
                    if (ds.Tables[0].Rows.Count > 0)
                    {

                            ListBox1.DataSource = ds;
                    
                            ListBox1.DataTextField = "Descr";
                    
                            ListBox1.Visible = true;
                    
                            lstbxLecturers.Visible = false;
                    
                            ListBox1.DataBind();
                        }
                        else
                        {
                    
                            //Leave it there Way it is
                            ListBox1.Visible = false;
                    
                            lstbxLecturers.Visible = true;
                        }
                    

                    And when i debug this , it says there are records, but i cant understand why dont they get populated in ListBox1 Thanks

                    Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

                    A Offline
                    A Offline
                    Abhijit Jana
                    wrote on last edited by
                    #10

                    No Luck ! I didn't find issue with that, even I have tried with Dataset :( Are you generating the list box at runtime ?

                    cheers, Abhijit CodeProject MVP

                    V 1 Reply Last reply
                    0
                    • M monu nair

                      so your question solved now or not.

                      Mahendra Bisht.

                      V Offline
                      V Offline
                      Vimalsoft Pty Ltd
                      wrote on last edited by
                      #11

                      Not Solved.

                      Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

                      1 Reply Last reply
                      0
                      • A Abhijit Jana

                        No Luck ! I didn't find issue with that, even I have tried with Dataset :( Are you generating the list box at runtime ?

                        cheers, Abhijit CodeProject MVP

                        V Offline
                        V Offline
                        Vimalsoft Pty Ltd
                        wrote on last edited by
                        #12

                        Meaning Populating the Listbox at run time ? Yes like this

                        private void Bind_Tags_List()
                        {

                            //Bind the listbox that Contains the Tags 
                            BLL.BLL obj = new BLL.BLL();
                        
                            String DB = Convert.ToString(Session\["ActiveDatabase"\]);
                        
                            try
                            {
                        
                                DataSet ds = obj.Get\_Tag\_Staff\_Only(DB);
                        
                                lstbxTags.DataSource = ds;
                        
                                lstbxTags.DataTextField = "DESCR";
                        
                                lstbxTags.DataBind();
                        
                        
                            }
                            catch (SqlException ex)
                            {
                                lblAdminStatus.Text = ex.Message.ToString();
                            }
                        }
                        

                        On page load Thanks

                        Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

                        A 1 Reply Last reply
                        0
                        • V Vimalsoft Pty Ltd

                          Meaning Populating the Listbox at run time ? Yes like this

                          private void Bind_Tags_List()
                          {

                              //Bind the listbox that Contains the Tags 
                              BLL.BLL obj = new BLL.BLL();
                          
                              String DB = Convert.ToString(Session\["ActiveDatabase"\]);
                          
                              try
                              {
                          
                                  DataSet ds = obj.Get\_Tag\_Staff\_Only(DB);
                          
                                  lstbxTags.DataSource = ds;
                          
                                  lstbxTags.DataTextField = "DESCR";
                          
                                  lstbxTags.DataBind();
                          
                          
                              }
                              catch (SqlException ex)
                              {
                                  lblAdminStatus.Text = ex.Message.ToString();
                              }
                          }
                          

                          On page load Thanks

                          Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

                          A Offline
                          A Offline
                          Abhijit Jana
                          wrote on last edited by
                          #13

                          Vuyiswa Maseko wrote:

                          Meaning Populating the Listbox at run time ? Yes

                          I want to mean creating the List Box Control ? Are you creating the Listbox at runtime ?

                          Vuyiswa Maseko wrote:

                          On page load

                          :confused:

                          cheers, Abhijit CodeProject MVP

                          V 2 Replies Last reply
                          0
                          • A Abhijit Jana

                            Vuyiswa Maseko wrote:

                            Meaning Populating the Listbox at run time ? Yes

                            I want to mean creating the List Box Control ? Are you creating the Listbox at runtime ?

                            Vuyiswa Maseko wrote:

                            On page load

                            :confused:

                            cheers, Abhijit CodeProject MVP

                            V Offline
                            V Offline
                            Vimalsoft Pty Ltd
                            wrote on last edited by
                            #14

                            No am not creating the Listbox control at runtime , but populating it at Runtime. I have Notice something String. When i select Something from the lstbxTags nothing get Displayed in the ListBox1 and when i select other Control that has no code in it in my page like a button , the ListBox1 gets Populated.

                            Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

                            1 Reply Last reply
                            0
                            • A Abhijit Jana

                              Vuyiswa Maseko wrote:

                              Meaning Populating the Listbox at run time ? Yes

                              I want to mean creating the List Box Control ? Are you creating the Listbox at runtime ?

                              Vuyiswa Maseko wrote:

                              On page load

                              :confused:

                              cheers, Abhijit CodeProject MVP

                              V Offline
                              V Offline
                              Vimalsoft Pty Ltd
                              wrote on last edited by
                              #15

                              I found the Problem; the Problem is that one of my Listboxes had a Autopostback property to False. I can’t believe that I spent the whole day trying to solve this problem and change my code, but still. I think this is one of those days Thank you for your Help

                              Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

                              A 1 Reply Last reply
                              0
                              • V Vimalsoft Pty Ltd

                                I found the Problem; the Problem is that one of my Listboxes had a Autopostback property to False. I can’t believe that I spent the whole day trying to solve this problem and change my code, but still. I think this is one of those days Thank you for your Help

                                Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za www.ITS.co.za

                                A Offline
                                A Offline
                                Abhijit Jana
                                wrote on last edited by
                                #16

                                :-D :omg:

                                cheers, Abhijit CodeProject MVP

                                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