protected void AlphabetizeDropDownListAndRemoveDuplicates(DropDownList ThisDropDownList)
{
SortedList AlphabetizedItems = new SortedList();
foreach (ListItem ThisListItem in ThisDropDownList.Items) {
if (AlphabetizedItems.Contains(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Strings.Trim(ThisListItem.Text))) == false) {
AlphabetizedItems.Add(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Strings.Trim(ThisListItem.Text)), ThisListItem.Value);
}
}
ThisDropDownList.Items.Clear();
foreach (DictionaryEntry AlphabetizedItem in AlphabetizedItems) {
ThisDropDownList.Items.Add(new ListItem(AlphabetizedItem.Key, AlphabetizedItem.Value));
}
}
Alphabetize drop down list and remove duplicate items.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment