Wednesday, August 1, 2007

Clearing Items in Repeater (or other) Control in .Net 2.0

You might notice that a repeater does not have an Items.Remove() or an Items.Clear() or even an Items[i].Remove() where you can loop through the collection and remove them one at a time. Nope, clearing a repeater is even easier than that.

I have a search control that dumps the results in a repeater, and to clear the results between search, I use the following line in my search click event:

myRepeater.DataSource = null;

whoop there it is :)