how can I check if the value is already present in a list-box, so that I can avoid duplicates?
I've added some values to the server-side list-box already, and when I add to list I get more duplicates.
How do I avoid duplicates?
lst_Viewers.Items.Add(reader["Name"].ToString());
ListItem item = new ListItem(reader["Name"].ToString());
if ( ! lst_Viewers.Items.Contains(item) ){
lst_Viewers.Items.Add(item);
}
or
var name = reader["Name"].ToString();
ListItem item = lst_Viewers.Items.FindByText(name);
if ( item == null ){
lst_Viewers.Items.Add(new ListItem(name));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With