How to check if an item already exists in a listbox? Give an Example
ASP.NET
3
Posts
3
Posters
0
Views
1
Watching
-
Hi there, The
Items
property of the ListBox control is of theListItemCollection
classs, and this class supports some utility methods which you can use do that likeContains
..., In addition, you can walk through the item collection and do the checking. For more information, see ListItemCollection Members[^] -
You can use the ListItemCollection's FindByValue/FindByText methods to see if a value exists in the ListBox. eg. if(null==ListBox1.Items.FindByValue(NewItem.Value))ListBox1.Items.Add(NewItem)