Directly it is not possible. You will have to take help of LINQ. In the below exampe I am selecting Apple using "pple"string
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="Mango" Value="Mango" />
<asp:ListItem Text="Apple" Value="Apple" />
<asp:ListItem Text="Orange" Value="Orange" />
</asp:DropDownList>
Method 1: Using Linq
C#
protected void Page_Load(object sender, EventArgs e)
{
string searchTerm = "pple";
ListItem item = (from i in DropDownList1.Items.Cast<ListItem>()
where ((ListItem)i).Value.Contains(searchTerm)
select i).FirstOrDefault() as ListItem;
DropDownList1.ClearSelection();
DropDownList1.Items.FindByValue(item.Value).Selected = true;
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim searchTerm As String = "pple"
Dim item As ListItem = TryCast(( _
Where DirectCast(i, ListItem).Value.Contains(searchTerm)).FirstOrDefault(), ListItem)
DropDownList1.ClearSelection()
DropDownList1.Items.FindByValue(item.Value).Selected = True
End Sub
Method 2: Using Loop
C#
protected void Page_Load(object sender, EventArgs e)
{
string searchTerm = "pple";
DropDownList1.ClearSelection();
foreach (ListItem item in DropDownList1.Items)
{
if (item.Value.Contains(searchTerm))
{
DropDownList1.Items.FindByValue(item.Value).Selected = true;
}
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim searchTerm As String = "pple"
DropDownList1.ClearSelection()
For Each item As ListItem In DropDownList1.Items
If item.Value.Contains(searchTerm) Then
DropDownList1.Items.FindByValue(item.Value).Selected = True
End If
Next
End Sub