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. using SelectedIndex to determine if an item was selected

using SelectedIndex to determine if an item was selected

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

    I'm using the selectedIndex of a drop down list to determine if the user select an item If dropdownlistMember.SelectedIndex > -1 do a bunch of stuff else send an error message to the user Its a zero based drop down list The problem is that SelectedIndex is never -1. If I step through the code, when the user does not make a selection, the index is 0. If they select the first item, the index is 0 ( it should be) If they select the second item, index is 1 ( it should be) I tried initializing the index during page load if not post back If Page.IsPostBack = False Then dlIdNums.SelectedIndex = -1 But index is always 0 Any ideas? thanks

    R 1 Reply Last reply
    0
    • S ssbelfast

      I'm using the selectedIndex of a drop down list to determine if the user select an item If dropdownlistMember.SelectedIndex > -1 do a bunch of stuff else send an error message to the user Its a zero based drop down list The problem is that SelectedIndex is never -1. If I step through the code, when the user does not make a selection, the index is 0. If they select the first item, the index is 0 ( it should be) If they select the second item, index is 1 ( it should be) I tried initializing the index during page load if not post back If Page.IsPostBack = False Then dlIdNums.SelectedIndex = -1 But index is always 0 Any ideas? thanks

      R Offline
      R Offline
      Ramasubramaniam
      wrote on last edited by
      #2

      Add a new item in the drop down with ' ' as the text and value as -1, that should be first item in the drop down. I was having the same problem i did this way. Ram

      S 2 Replies Last reply
      0
      • R Ramasubramaniam

        Add a new item in the drop down with ' ' as the text and value as -1, that should be first item in the drop down. I was having the same problem i did this way. Ram

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

        great - thanks for the idea

        1 Reply Last reply
        0
        • R Ramasubramaniam

          Add a new item in the drop down with ' ' as the text and value as -1, that should be first item in the drop down. I was having the same problem i did this way. Ram

          S Offline
          S Offline
          ssbelfast
          wrote on last edited by
          #4

          can't get this to work The drop down list is populated when the program is run ( by reading in records from a table) I add a new item with text ' ' and value = '1 but when I step through the code, the first item always has an index = 0 even though I've just set it to -1 Don't understand how to change this Even if no item is selected, the index is = 0 which means if no item is selected, the first item will always be selected

          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