Protected Sub AlphabetizeDropDownListAndRemoveDuplicates(ThisDropDownList As DropDownList)
Dim AlphabetizedItems As New SortedList
For Each ThisListItem As ListItem In ThisDropDownList.Items
If AlphabetizedItems.Contains(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Trim(ThisListItem.Text))) = False Then
AlphabetizedItems.Add(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Trim(ThisListItem.Text)), ThisListItem.Value)
End If
Next ThisListItem
ThisDropDownList.Items.Clear()
For Each AlphabetizedItem As DictionaryEntry In AlphabetizedItems
ThisDropDownList.Items.Add(New ListItem(AlphabetizedItem.Key, AlphabetizedItem.Value))
Next AlphabetizedItem
End Sub
Tips and tricks for .NET using ASP and VB code.
Alphabetize drop down list and remove duplicate items.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment