Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > dropdown losing selected index value

Reply
Thread Tools

dropdown losing selected index value

 
 
Steve Hershoff
Guest
Posts: n/a
 
      11-10-2006
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?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help to fill textboxes from a selected item in datagrid-selected index changed. mldardy ASP .Net 0 09-28-2010 02:59 PM
dropdown losing selected index value Steve Hershoff ASP .Net Web Controls 0 11-10-2006 07:34 PM
custom dropdown problems keeping selected index and lisitems jason.hau@gmail.com ASP .Net 0 09-01-2006 03:31 PM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
Problem changing the selected index property on a dropdown control Simon Harvey ASP .Net 4 11-15-2004 04:57 PM



Advertisments