DropDownList in FormView Edit Template behaves unexpectedly

P

peter.drienovsky

Hello,

I'll try to describe my problem in simplest possible terms.

I have:
- FormView databound via LinqDataSource (linq to sql)
- 2 DropDownList (A, B) inside FormView's EditTemplate, both databound
using 2 different LinqDataSources (also linq to sql)
- A and B has AutoPostback and EnableViewstate set to 'true'

My final intention is to make hierarchical DDLs (citiest in A, streets
in B for instance), however, I was not able to go so far as I
encountered essential problems. These can be characterized by specific
behavior of DDLs:


I.
Suppose that both DDLs have selected index other than 0.
Change selection in A to some index other than 0.
Then both DDLs will fire SelectedIndexChanged event (!)

II.
Suppose that both DDLs have selected index other than 0.
Change selection in A to index 0.
Only B will fire SelectedIndexChanged event (!)

III.
Suppose that A has selected index other than 0 while B has selected
index 0.
Change selection in A to index 0.
None of DDLs will fire SelectedIndexChanged event (!)

Conclusion:
Every DDL is firing SelectedIndexChanged on every Postback (no matter
if it is reason of PostBack) with one exception - when it's selected
index is or has been changed to 0.

Theorization:
Server databind DDL on every postback (this is really true for DDL
inside ViewForm) dropping information about originally selected index
of DDL replacing it with default 0.
Server then does not compare originally selected value with currently
selected value coming from viewstate to figure out if
SlectedIndexChange should fire, but it compares right-after-binding
default 0 value of selected index of DDL with currently selected value
coming from viewstate. Outcome is as described above.
This is just my theory, I have not approve it by debugging to
necessary level of details.


Be it so or not.... what a mess : (

I need SelectedIndexChanged of A to re-databind B to create
hierarchical pair of dropdownlists.
However, behavior described above is completely inappropriate as a
basis for building such a mechanism.


Do you guys have some suggestions hove to resolve this?

Many thanks.


Peter.
 
P

peter.drienovsky

I've found a workaround.

As normal SelectedIndexChanged is compromised in the scenario
described,
I've decided to simulate it by other means.

I am using PreRender event of DroDownList to determine if selected
index has
changed since previous postback. I do this by comparing current
SelectedIndex
with the one I have stored in the ViewState on the previous PostBack.
If the
index has changed, I execute code that would normally reside in
SelectedIndexChange event handler.

This workaround has only few hours, that is why I hope I am not going
to
reveal some serious unwanted sideeffects.

However, this is still only a workaround and I am pretty frustrated of
how
unhandy can DropDownList become once one puts it into a FormView. I've
been
stuck in seemingly ten-minutes task for almost a week.

If you were able to get some more insight into the problem, please
share it
with us.

Thanks.

Peter.
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top