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. 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. Jordan
    Replies:
    2
    Views:
    2,577
    Jordan
    Feb 10, 2004
  2. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    order of events - dynamic checkbox events

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Aug 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    601
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Aug 17, 2005
  3. Bill Sexton
    Replies:
    1
    Views:
    416
    Bill Sexton
    Jan 26, 2007
  4. JcFx
    Replies:
    0
    Views:
    319
  5. Chris

    Events Events Events Please Help

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

Share This Page