Clearing selected items in Listbox

  • Thread starter Thread starter anony
  • Start date Start date
A

anony

Hi,

Is there a method to clear the selected items in a Listbox web control? It
appears that ClearSelected() is for Windows Forms only.

Thanks,
Brian
 
This appears to remove the items from the list. I want to retain the items,
just clear all items from being selected.

Thanks,
Brian
 
ooh! sorry I misread your question,

You can iterate through the items collection and set all the
items.selected=false

dim li as listitem
for each li in myListbox.Items
li.selected=false
next
 
Don't know the C# equivalent but this works:

Dim lstItem As ListItem

For Each lstItem In ListBox1.Items

lstItem.Selected = False

Next



HTH



Harry Simpson
 
Will do.. thanks.


Raterus said:
ooh! sorry I misread your question,

You can iterate through the items collection and set all the
items.selected=false

dim li as listitem
for each li in myListbox.Items
li.selected=false
next
 
My bad. I had dropdownlist in mind. I don't program in v1.1, still
chugging away in 1.0 which has no ASP.NET ListBox control.

Can you set the SelectedIndex to -1, maybe? To me, there has to be a more
efficient way than looping through all the items.
 
Score! That works.

Thanks!

hb said:
My bad. I had dropdownlist in mind. I don't program in v1.1, still
chugging away in 1.0 which has no ASP.NET ListBox control.

Can you set the SelectedIndex to -1, maybe? To me, there has to be a more
efficient way than looping through all the items.
 
Back
Top