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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. DropownList Not workin'

DropownList Not workin'

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

    I have a DropdownList I bind data to it at runtime. It alls well but when I select some value and click on a button, I need to pass the selected value to the next page in a query string but the first value reagardless of what I select is passed like,

    btn_Click(..)
    {
    Response.Redirect("XYZ.aspx?ID=" + Dropdwn1.SelectedValue.ToString())
    }

    But the first value, which is 0, is passed no mater what I select I also tried a post back ie. I made the Dropdown to AutoPostBack=True and

    Private Sub drpdwn1_SelectedIndexChanged(..)
    Response.Write(drpdwn1.SelectedValue.ToString())
    End Sub

    But still the first value is writter not the one I select Help _____________________________________________________ Yea! I could be wrong...

    I 1 Reply Last reply
    0
    • S saud_a_k

      I have a DropdownList I bind data to it at runtime. It alls well but when I select some value and click on a button, I need to pass the selected value to the next page in a query string but the first value reagardless of what I select is passed like,

      btn_Click(..)
      {
      Response.Redirect("XYZ.aspx?ID=" + Dropdwn1.SelectedValue.ToString())
      }

      But the first value, which is 0, is passed no mater what I select I also tried a post back ie. I made the Dropdown to AutoPostBack=True and

      Private Sub drpdwn1_SelectedIndexChanged(..)
      Response.Write(drpdwn1.SelectedValue.ToString())
      End Sub

      But still the first value is writter not the one I select Help _____________________________________________________ Yea! I could be wrong...

      I Offline
      I Offline
      israeli
      wrote on last edited by
      #2

      DropDownList in ASP.NET has a bug. If there are 2 or more items with the same value property the SelectedIndex property is not returning the index of the focued item, as it should, but the index of the first item in the list which has got the same value property as the value of the focused one. For example if item 2 has value="a" and item 8 has got also value="a" then when you select item 8 the following code: DDL.items[DDL.SelectedItem].text is showing the text of item 2 !. Check if the same happens with the property SelectedValue.

      S 1 Reply Last reply
      0
      • I israeli

        DropDownList in ASP.NET has a bug. If there are 2 or more items with the same value property the SelectedIndex property is not returning the index of the focued item, as it should, but the index of the first item in the list which has got the same value property as the value of the focused one. For example if item 2 has value="a" and item 8 has got also value="a" then when you select item 8 the following code: DDL.items[DDL.SelectedItem].text is showing the text of item 2 !. Check if the same happens with the property SelectedValue.

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

        Hello, No I do not have the same values for even 2 of DropdownList Values. No other value, other than the 1st has the value=0, all others are strings like 'ID-02342' etc. But the problem still remains _____________________________________________________ Yea! I could be wrong...

        D 1 Reply Last reply
        0
        • S saud_a_k

          Hello, No I do not have the same values for even 2 of DropdownList Values. No other value, other than the 1st has the value=0, all others are strings like 'ID-02342' etc. But the problem still remains _____________________________________________________ Yea! I could be wrong...

          D Offline
          D Offline
          Daniel Santillanes
          wrote on last edited by
          #4

          I think may be you have an initialization in Page_Load event that's executed everytime there's a post. That happened to me before, for example: private sub Page_Load(x as object, x as eventargs) binddropdownmethod() end sub change it to: private sub Page_Load(x as object, x as eventargs) if not ispostback then binddropdownmethod() end if end sub Look at it, I'm almost sure that somewhere in your code, the dropdown must be binding to data before going into the button's event, and this resets the selection done. daniero

          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