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. selected index changed in listbox control

selected index changed in listbox control

Scheduled Pinned Locked Moved ASP.NET
databasehelp
5 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
    shabonaa
    wrote on last edited by
    #1

    hii, i placed the listbox control in the webform. and i added some code in the ListBox1_SelectedIndexChanged but the problem that when i select the different items in the list it doesn't infoke the methode and i tried to debuge it and i found that the selectedindex is always = -1

    K 1 Reply Last reply
    0
    • S shabonaa

      hii, i placed the listbox control in the webform. and i added some code in the ListBox1_SelectedIndexChanged but the problem that when i select the different items in the list it doesn't infoke the methode and i tried to debuge it and i found that the selectedindex is always = -1

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

      Did you set autopostback to true on the listbox? Ben

      S 1 Reply Last reply
      0
      • K kubben

        Did you set autopostback to true on the listbox? Ben

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

        i tried to set autopostback to true and works for the pre defined items in the collection in design mode but if in run time if i clear the listbox items and fill it in the run time using the .Add() method it give me selectedindex=-1

        K 1 Reply Last reply
        0
        • S shabonaa

          i tried to set autopostback to true and works for the pre defined items in the collection in design mode but if in run time if i clear the listbox items and fill it in the run time using the .Add() method it give me selectedindex=-1

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

          It sounds like in the page_load method you are populating the listbox. You need to have some code that checks for postback. Something like:

          If (!IsPostBack)
          {
          //then add items to listbox
          }

          Otherwise you are constantly re-loading your listbox everytime you postback to the web server not just the first page load. Hope that helps. Ben

          S 1 Reply Last reply
          0
          • K kubben

            It sounds like in the page_load method you are populating the listbox. You need to have some code that checks for postback. Something like:

            If (!IsPostBack)
            {
            //then add items to listbox
            }

            Otherwise you are constantly re-loading your listbox everytime you postback to the web server not just the first page load. Hope that helps. Ben

            S Offline
            S Offline
            shabonaa
            wrote on last edited by
            #5

            dear kunnen first thanks for replay. i discovered the problem, the problem that i was clearing the list items and load the list in page load. so when i select the item the reload again then clear the list and this point the selectedindex goes -1 . so i put a condition that let it clear the list only one time when the page open thanks again

            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