embeding databound DropDownList in FormView spoils DropDownList ev

Discussion in 'ASP .Net Web Controls' started by Lagrange, Jan 16, 2009.

  1. Lagrange

    Lagrange Guest

    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.
    Lagrange, Jan 16, 2009
    #1
    1. Advertising

  2. Lagrange

    Lagrange Guest

    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.
    Lagrange, Jan 17, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    embeding wmp w/instant play?l

    Guest, Jun 10, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    354
    Curt_C [MVP]
    Jun 10, 2005
  2. Jeff

    the DataBound event of FormView

    Jeff, Aug 29, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    12,346
  3. rodchar
    Replies:
    0
    Views:
    382
    rodchar
    Nov 26, 2007
  4. David C

    FormView Null databound value

    David C, Dec 7, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    373
    Phil H
    Dec 8, 2007
  5. Manu
    Replies:
    0
    Views:
    161
Loading...

Share This Page