Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > embeding databound DropDownList in FormView spoils DropDownList ev

Reply
Thread Tools

embeding databound DropDownList in FormView spoils DropDownList ev

 
 
Lagrange
Guest
Posts: n/a
 
      01-16-2009
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.

 
Reply With Quote
 
 
 
 
Lagrange
Guest
Posts: n/a
 
      01-17-2009
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.
 
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
FormView Null databound value David C ASP .Net 1 12-08-2007 09:49 PM
databound custom controls vs composite databound custom controls rodchar ASP .Net 0 11-26-2007 03:51 PM
Formview within Formview Chris ASP .Net 0 05-19-2007 04:12 PM
the DataBound event of FormView Jeff ASP .Net 3 08-29-2006 10:50 PM
templated databound control problem - not showing databound Manu ASP .Net Web Controls 0 05-22-2006 09:46 AM



Advertisments