What is order of events during data binding?

T

Tony Z

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?
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top