[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Thomas Scheiderich

2/20/2004 7:20:00 PM

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.

3 Answers

Ken Cox [MS MVP]

2/21/2004 2:05:00 AM

0

The problem seems to be invisible line breaks, tabs or other characters
preceding the text.

If you make sure there's nothing between the tags except the text you want,
it seems to work:

<asp:listitem value="100">CD-ROM Drive - $100</asp:listitem>

Ken
MVP [ASP.NET]


"Thomas Scheiderich" <tfs@deltanet.com> wrote in message
news:40365DC4.1030302@deltanet.com...
>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.
>

Thomas Scheiderich

2/21/2004 4:59:00 AM

0

Ken Cox [Microsoft MVP] wrote:

> The problem seems to be invisible line breaks, tabs or other characters
> preceding the text.
>
> If you make sure there's nothing between the tags except the text you
> want, it seems to work:
>
> <asp:listitem value="100">CD-ROM Drive - $100</asp:listitem>
>

Yup, that was it.

Could've also been the 3 spaces on the next line.

Thanks,

Tom.


> Ken
> MVP [ASP.NET]
>
>
> "Thomas Scheiderich" <tfs@deltanet.com> wrote in message
> news:40365DC4.1030302@deltanet.com...
>
>> 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.
>>
>

Ken Cox [MS MVP]

2/21/2004 3:00:00 PM

0

The weird part was that trim() didn't seem to catch the whitespace. In a
sense, the VS.NET editor is at fault for allowing broken lines there.

"Thomas Scheiderich" <tfs@deltanet.com> wrote in message
news:4036E598.4070800@deltanet.com...
> Ken Cox [Microsoft MVP] wrote:
>
>> The problem seems to be invisible line breaks, tabs or other characters
>> preceding the text.
>>
>> If you make sure there's nothing between the tags except the text you
>> want, it seems to work:
>>
>> <asp:listitem value="100">CD-ROM Drive - $100</asp:listitem>
>>
>
> Yup, that was it.
>
> Could've also been the 3 spaces on the next line.
>
> Thanks,
>
> Tom.
>
>