Rick
asked on
asp.net - select items in a listbox in code
Is there a way to select items in a listbox without having to loop through the whole list?
For Each item As ListItem In lstBxBrand.Items
If item.Text = "Dell" Or item.Text = "HP" Or item.Text = "Sony" Then
item.Selected = True
End If
Next
Thank you.
For Each item As ListItem In lstBxBrand.Items
If item.Text = "Dell" Or item.Text = "HP" Or item.Text = "Sony" Then
item.Selected = True
End If
Next
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ListItem li = ListBox1.Items.FindByText( "Dell"); // also FindByValue
li.Selected = true;
or
ListBox1.Items[5].Selected = true;
or
ListBox1.SelectedIndex = 5;
li.Selected = true;
or
ListBox1.Items[5].Selected
or
ListBox1.SelectedIndex = 5;
Open in new window