Thursday, March 29, 2012

manually removing ALL items from dropdownlist

Hi I want to loop through and manually remove all the items from a dropdownlist, I want to leave the viewstate on the control though as it is required most of the time. Here is the code that i thought should work but as you have guessed it doesn't the error produced is:

"Collection was modified; enumeration operation may not execute."


Dim item As ListItem
For Each item In drpPrivate.Items
drpPrivate.Items.Remove(item)
Next item

Please could you tell me how to remove all the items from a dropdownlist without resorting to EnableViewState="false"


drpPrivate.Items.Clear()

0 comments:

Post a Comment