dropdown losing selected index value

Discussion in 'ASP .Net Web Controls' started by Steve Hershoff, Nov 10, 2006.

  1. Hi everyone,

    I have a dropdown control in a DataList that for some reason "loses" its
    index value during postback. I'm not quite sure why.

    First, a little talk about the structure of the DataList: it has several
    other dropdowns besides the one I'm interested in. One of them has its
    index set to zero on every postback, no matter what, and in its
    OnSelectedIndexChanged function it calls DataBind() on my troublesome
    dropdown.

    Think of it like two cascading dropdowns: dropdown A, and my dropdown B,
    the misbehaving one. If dropdown A's index changes, it calls DataBind on
    dropdown B. dropdown B uses a separate DataSource from the DataList,
    created via a function that's listed declaritively in the aspx form.

    So a typical use case involves my selecting a value from dropdown B, which
    forces an automatic page postback. (Autopostback = true for the control) In
    the Page_Load method the DataList is bound, which binds dropdown A, and as I
    mentioned above, A's selected index is set to zero. This in turn fires off
    dropdown A's OnSelectedIndexChanged function, which calls DataBind() on
    dropdown B.

    I don't know if doing that resets dropdown B's selected index value, but by
    the time dropdown B's OnSelectedIndexChanged is finally called the
    SelectedIndex property has been reset to zero, which is definitely *not* the
    value I selected on the form. Does anyone know why this is, and how I can
    hold the proper SelectedIndex value all the way through?

    I realize my scenario above sounds is a little hard to digest, so any help
    you can give would be greatly appreciated. I think the key question here
    is: does calling DataBind() on a dropdown control invalidate the
    SelectedIndex property set via a postback?
    Steve Hershoff, Nov 10, 2006
    #1
    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. Simon Harvey
    Replies:
    4
    Views:
    460
    Simon Harvey
    Nov 15, 2004
  2. vishnu
    Replies:
    1
    Views:
    1,202
    Patrick.O.Ige
    Mar 25, 2006
  3. Replies:
    0
    Views:
    353
  4. mldardy
    Replies:
    0
    Views:
    961
    mldardy
    Sep 28, 2010
  5. Steve Hershoff

    dropdown losing selected index value

    Steve Hershoff, Nov 10, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    737
    Steve Hershoff
    Nov 10, 2006
Loading...

Share This Page