embeding databound DropDownList in FormView spoils DropDownList ev

L

Lagrange

Hello,

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

I have:

- FormView databound via LinqDataSource (linq to sql)
- 2 DropDownLists (A, B) inside FormView's EditTemplate
- both A and B 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), however, I was not able to go any further as I encountered essential
problems. These can be characterized by specific behavior of DDLs (while
inspecting the behavior, A and B are not hierarchically bound yet):

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 (!) (Only A should fire SelectedIndexChanged event)

II. Suppose that both DDLs have selected index other than 0. Change
selection in A to index 0. B and ONLY B will fire SelectedIndexChanged event
(!) (Only A should 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 (!) (Only A should fire SelectedIndexChanged event)

(You can swap A and B in previous tests, none of them is significant.)

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

Theorization: Server databinds each DDL on every postback (this is really
true for databound DDL inside databound ViewForm) dropping information about
originally selected index of DDL replacing it with default 0. Server then
does not compare originally selected value with new 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
new currently selected value coming from viewstate. Outcome is as described
above. This is just my theory, I have not approve it by debugging at
sufficient level of details.

Behavior described above is completely inappropriate as a basis for building
hierarchically bound DDLs as I need SelectedIndexChanged of A to re-databind
B to create hierarchical pair of dropdownlists. It completely invalidates
SelectedIndexChanged event as an indication of DDL's selected index change.

Do you have some suggestions how to resolve this issue?

Many thanks.

Peter.
 
L

Lagrange

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,931
Messages
2,570,085
Members
46,536
Latest member
keelop

Latest Threads

Top