K
Ken Cox [Microsoft MVP]
Hi Matt,
One way is to use the FindByText method of the ddl. It looks through the
items and tries to find a match (case-sensitive).
If the item is Nothing, there's no match. If it returns an object, you've
found what you were after. Here's some code that shows what I mean:
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim lstItem As ListItem
lstItem = DropDownList1.Items.FindByText _
(TextBox1.Text)
If IsNothing(lstItem) Then
Label1.Text = "Not Found"
Else
Label1.Text = "Found"
End If
End Sub
<form id="Form1" method="post" runat="server">
<P>
<asp
ropDownList id="DropDownList1" runat="server">
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
</asp
ropDownList></P>
<P>
<asp:TextBox id="TextBox1" runat="server">Yellow</asp:TextBox></P>
<P>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
<P>
<asp:Button id="Button1" runat="server" Text="Find"></asp:Button></P>
</form>
Does this help?
Ken
Microsoft MVP [ASP.NET]
One way is to use the FindByText method of the ddl. It looks through the
items and tries to find a match (case-sensitive).
If the item is Nothing, there's no match. If it returns an object, you've
found what you were after. Here's some code that shows what I mean:
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim lstItem As ListItem
lstItem = DropDownList1.Items.FindByText _
(TextBox1.Text)
If IsNothing(lstItem) Then
Label1.Text = "Not Found"
Else
Label1.Text = "Found"
End If
End Sub
<form id="Form1" method="post" runat="server">
<P>
<asp
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
</asp
<P>
<asp:TextBox id="TextBox1" runat="server">Yellow</asp:TextBox></P>
<P>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
<P>
<asp:Button id="Button1" runat="server" Text="Find"></asp:Button></P>
</form>
Does this help?
Ken
Microsoft MVP [ASP.NET]