listbox woes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,

i have a listbox on my .aspx page and when i highlight an item in the
listbox should i just be able to loop thru the items collection of the
listbox and delete what is selected? it's not letting me do that for some
reason i keep getting an error saying:
Collection was modified; enumeration operation may not execute.

what's the best way to do the delete?

thanks,
rodchar
 
You can't delete items from the collection that you are looping through.
Get the collection of selected items and use the ToArray method to get
them in an array. Loop through the array and remove each item from the
collection.
 
thank you.


Göran Andersson said:
You can't delete items from the collection that you are looping through.
Get the collection of selected items and use the ToArray method to get
them in an array. Loop through the array and remove each item from the
collection.
 
Back
Top