FindByText not working

T

Thomas Scheiderich

I have a screen that is trying to search a listbox both by FindByText
and FindByValue. The FindByValue is working find, but the FindByText is
not finding anything. This is even if I copy the text directly from the
source page and paste it into the textbox to make sure I have no typos.

Here is the screen:

*******************************************************************
<%@Page Explicit="True" Language="VB" Debug="True" %>

<html>
<script runat="server">
Sub OK_Click(Sender As Object, E As EventArgs)
Dim Total, ItemIndex As Integer
Message.Text = "You chose:<br>"
Total = 1000
For ItemIndex = 0 To PCOptions.Items.Count -1
If PCOptions.Items(ItemIndex).Selected = True Then
Message.Text = Message.Text & _
PCOptions.Items(ItemIndex).Text & "<br>"
Total = Total + PCOptions.Items(ItemIndex).Value
End If
Next
Message.Text = Message.Text & "Your total is $" & Total
End Sub

Sub Find_Click(Sender As Object, E As EventArgs)
Dim FoundItem As ListItem

FoundItem = PCOptions.Items.FindByText(FindText.Text)
if Not isNothing(FoundItem) Then
Message2.text = FoundItem.text
else
Message2.text = "Nothing found for - " & FindText.Text
end if
End Sub

Sub Find_Click2(Sender As Object, E As EventArgs)
Dim FoundItem2 As ListItem

FoundItem2 = PCOptions.Items.FindByValue(FindText2.Text)
if Not isNothing(FoundItem2) Then
Message3.text = FoundItem2.text
else
Message3.text = "Nothing found for - " & FindText2.Text
end if
End Sub

</script>

<body>
<h1>Personalize Your PC</h1>
Thanks for deciding to purchase our choice,
one-of-a-kind Generic PC for a base price of only
$1000. Now you can pick from the following options
you'd like to add.<br>
<form runat="server">
<asp:listbox id="PCOptions" selectionmode="multiple"
runat="server">
<asp:listitem value="100">
CD-ROM Drive - $100</asp:listitem>
<asp:listitem value="200">
19 Inch Monitor - $200</asp:listitem>
<asp:listitem value="150">
Ink Jet Printer - $150</asp:listitem>
<asp:listitem value="50">
Joystick - $50</asp:listitem>
<asp:listitem value="100">
128MB More RAM - $100</asp:listitem>
</asp:listbox><br><br>
<asp:button id="OKButton" text="OK" runat="server"
onclick="OK_Click" /><br><br>
<asp:textbox id="FindText" runat="server" /> <asp:button
id="findButton" text="Find by text" runat="server"
onclick="Find_Click" /><br><br>
<asp:textbox id="FindText2" runat="server" /> <asp:button
id="findButton2" text="Find by value" runat="server"
onclick="Find_Click2" /><br><br>
<asp:label id="Message" runat="server" /><br>
<asp:label id="Message2" runat="server" /><br>
<asp:label id="Message3" runat="server" /><br>
</form>
</body>
</html>

*******************************************************************

The routine at issue is the "Find_Click" routine. The "Find_Click2"
routine works fine.

I can't see where I have screwed up (but I'm sure I have - I just can't
seem to find it).

Thanks,

Tom.
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top