dropdown losing selected index value

S

Steve Hershoff

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top