DropDownList is always returning the value from index 0

Discussion in 'ASP .Net' started by Nathan Sokalski, Sep 5, 2005.

  1. I have a DropDownList that is returning the value from index 0 regardless of
    which item is selected. The code that I am using to test which index it is
    returning is:

    Label1.Text = ddlDeleteEvents.SelectedIndex


    This is the first line of code in a Button's Click event handler, so I know
    that there is no other code changing the selected value before I use it.
    What is happening here? Any help would be appreciated. Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Sep 5, 2005
    #1
    1. Advertising

  2. Nathan,

    This is only a guess, but a very common oversight is binding the drop down
    list on every page load which resets the selected item.

    In your code, where you bind your drop down list, put:

    If Not Page.IsPostBack Then
    '---Bind your drop down here
    End If

    That should take care of it if my guess is correct.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Nathan Sokalski" <> wrote in message
    news:...
    >I have a DropDownList that is returning the value from index 0 regardless
    >of which item is selected. The code that I am using to test which index it
    >is returning is:
    >
    > Label1.Text = ddlDeleteEvents.SelectedIndex
    >
    >
    > This is the first line of code in a Button's Click event handler, so I
    > know that there is no other code changing the selected value before I use
    > it. What is happening here? Any help would be appreciated. Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    S. Justin Gengo, Sep 5, 2005
    #2
    1. Advertising

  3. You can access the text and value properties
    of the selected item in code like this :

    Dim strVar as String

    - To access the text

    strVar = DropDownList1.SelectedItem.Text

    - To access the value
    strVar = DropDownList1.SelectedItem.Value



    Juan T. Llibre
    ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    ==========================

    "Nathan Sokalski" <> wrote in message
    news:...
    >I have a DropDownList that is returning the value from index 0 regardless of which item
    >is selected. The code that I am using to test which index it is returning is:
    >
    > Label1.Text = ddlDeleteEvents.SelectedIndex
    >
    >
    > This is the first line of code in a Button's Click event handler, so I know that there
    > is no other code changing the selected value before I use it. What is happening here?
    > Any help would be appreciated. Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    Juan T. Llibre, Sep 5, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski

    DropDownList always returns value at index 0

    Nathan Sokalski, Sep 18, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    572
    Nathan Sokalski
    Sep 18, 2005
  2. Nathan Sokalski

    DropDownList is always returning the value from index 0

    Nathan Sokalski, Sep 5, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    209
    Juan T. Llibre
    Sep 5, 2005
  3. Nathan Sokalski

    DropDownList is always returning the value from index 0

    Nathan Sokalski, Sep 5, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    203
    Juan T. Llibre
    Sep 5, 2005
  4. Nathan Sokalski

    DropDownList always returns value at index 0

    Nathan Sokalski, Sep 18, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    346
    Cor Ligthert [MVP]
    Sep 18, 2005
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    359
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page