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. List Box

List Box

Scheduled Pinned Locked Moved C#
databasehelpquestion
4 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.
  • S Offline
    S Offline
    Sean89
    wrote on last edited by
    #1

    I have a list box control on a web form that displays some data from a database. Each time a different item is selected in this list box I want to display some data in another list box, so I am handeling the SelectedIndexChanged event. My problem is that the event doesn't seem to be firing. This is what I am using:

    protected void GroupList\_SelectedIndexChanged(object sender, EventArgs e)
    {
        //get what group has been selected
        int index = GroupList.SelectedIndex;
    
        // get all the items in the group
        DataRow\[\] rows = dSet.Tables\["Mounts"\].Select("Group\_Number =" + GroupList.Items\[index\].Text);
    
        // Clear the second list of any items
        foreach (ListItem item in MountList.Items)
        {
            MountList.Items.Remove(item);
        }
    
        //Display the new list
        foreach (DataRow row in rows)
        {
            MountList.Items.Add(row\[0\].ToString());
        }
    }
    

    When I run this and select different items in the list box, nothing happens. Any ideas why? Thanks for any responses ;)


    K 1 Reply Last reply
    0
    • S Sean89

      I have a list box control on a web form that displays some data from a database. Each time a different item is selected in this list box I want to display some data in another list box, so I am handeling the SelectedIndexChanged event. My problem is that the event doesn't seem to be firing. This is what I am using:

      protected void GroupList\_SelectedIndexChanged(object sender, EventArgs e)
      {
          //get what group has been selected
          int index = GroupList.SelectedIndex;
      
          // get all the items in the group
          DataRow\[\] rows = dSet.Tables\["Mounts"\].Select("Group\_Number =" + GroupList.Items\[index\].Text);
      
          // Clear the second list of any items
          foreach (ListItem item in MountList.Items)
          {
              MountList.Items.Remove(item);
          }
      
          //Display the new list
          foreach (DataRow row in rows)
          {
              MountList.Items.Add(row\[0\].ToString());
          }
      }
      

      When I run this and select different items in the list box, nothing happens. Any ideas why? Thanks for any responses ;)


      K Offline
      K Offline
      Kuira
      wrote on last edited by
      #2

      Possible clauses. - How you handle the initliazation. - If its running it on the server this function. - If this method isnt being added on the specific control.

      S 1 Reply Last reply
      0
      • K Kuira

        Possible clauses. - How you handle the initliazation. - If its running it on the server this function. - If this method isnt being added on the specific control.

        S Offline
        S Offline
        Sean89
        wrote on last edited by
        #3

        What initialization is there to be done?


        Sean :)

        K 1 Reply Last reply
        0
        • S Sean89

          What initialization is there to be done?


          Sean :)

          K Offline
          K Offline
          Kuira
          wrote on last edited by
          #4

          Well, more of the case of Web Forms how you need to check if your reloading those Listboxes again, and if so that whenever you reload the page again, it might reload those items again and reset whatever changes you want in the first place. Another issue becomes if its stateless or not (meaning does it retain the data when you press on buttons, that go back to the server to process things and spit back out the result on the WebForm that you asked for). Web Forms are really difficult to determine where your problem is. You need to check how the flow of the web form works, but from hazarding a guess of why nothing is happening is most possibly that you are resetting those listboxes to that nothing is happening. But this is just guessing, it'd be better with a full code rather than a specific method, but thats your call. Kuira

          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