Select item from drop down list using text

1.4k views Asked by At

I need to select an item from drop down list using its text. The problem is when I use below code, it selects the exact name only. What I want is:

Name
--------
abc
def
xyz

This is what I tried to do.

ddlSup.SelectedIndex = ddlSup.Items.IndexOf(ddlSup.Items.FindByText("a"))

When I write 'a' I want to get abc, in my case am getting nothing. Thanks.

1

There are 1 answers

0
Hideki On

try this:

    For Each Item In ComboBox1.Items
        If Item.ToString.Contains(TextBox1.Text) And TextBox1.Text.Trim <> "" Then
            ComboBox1.SelectedItem = Item
        ElseIf TextBox1.Text.Trim = "" Then
            ComboBox1.SelectedIndex = 0
        End If
    Next

you can modify this code, instead of using Contains function you can also use StartsWith or some string manipulation function available.