What is order of events during data binding?

Discussion in 'ASP .Net Web Controls' started by Tony Z, Mar 10, 2005.

  1. Tony Z

    Tony Z Guest

    I am trying to bind a DropDownList to a dataset and (basically at the same
    time) set the selected index of the list base on the value of a column from
    another dataset.
    The first problem I have had to overcome was getting the index of the item I
    want. I wrote following routine to do that:
    Function findIndex(ByRef droplist As DropDownList, ByVal value As String) As
    Integer
    Dim li As ListItem
    Dim i As Integer

    li = droplist.Items.FindByText(value)

    For i = 0 To droplist.Items.Count - 1
    If li.Equals(droplist.Items(i)) Then
    Return i
    End If
    Next i
    Return -1
    End Function

    I use it in the ASP code like this:
    <asp:dropdownlist id=PaymentTypeDrop runat="server" Width="128px"
    EnableViewState="False" DataSource="<%# PaymentTypeDS1 %>"
    DataTextField="Payment Type" SelectedIndex='<%# findIndex(PaymentTypeDrop,
    DataBinder.Eval(objpayDS, "Tables[Payments].DefaultView.[0].PaymentType"))
    %>' DataMember="Payment Type">
    </asp:dropdownlist>

    Now when I set a breakpoint at the Return -1 line, I discover that the
    DropDownList has yet to be populated. I therefore have to assume that the
    binding to fill the DropDownList has not yet taken place.

    How can I accomplish my goal?
     
    Tony Z, Mar 10, 2005
    #1
    1. Advertisements

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. Jordan
    Replies:
    2
    Views:
    2,760
    Jordan
    Feb 10, 2004
  2. Sheila Jones

    Event order during a postback

    Sheila Jones, Feb 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    516
    Sheila Jones
    Feb 19, 2004
  3. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    order of events - dynamic checkbox events

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Aug 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    771
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Aug 17, 2005
  4. Bill Sexton
    Replies:
    1
    Views:
    510
    Bill Sexton
    Jan 26, 2007
  5. traveller
    Replies:
    0
    Views:
    1,586
    traveller
    Jan 8, 2008
  6. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    610
    Dmitry Korolyov
    Sep 22, 2003
  7. JcFx
    Replies:
    0
    Views:
    539
  8. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    661
    Chris
    Aug 30, 2005
Loading...