The following is a collection of useful VB.NET (2003) functions:
sortListItems - This functions sorts a dropdownlist or listbox. It should
also sort any other control which has listitems but have only
tried it on those two mentioned above. This is a useful function
since the dropdownlist does not come with a sort method.
Private Sub sortListItems(ByVal list As Object)
' Create Variables
Dim li As ListItem
Dim sl As SortedList = New SortedList
' Loop through each Item in the List and move them over to the SortedList
For Each li In list.Items
sl.Add(li.Text, li.Value)
Next
' Move sorted items back to List again
list.DataSource = sl
list.DataValueField = "Value"
list.DataTextField = "Key"
list.DataBind()
End Sub
PDF Version