Bcktr Bcktr - 1 month ago 8
Vb.net Question

How to sort dropdownlist Currency List item that not related with database?

How to acecending sort the dropdownlist in currency list. Is need to datatable/dataview?

For Each cultureInfo__1 As CultureInfo In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
Dim regionInfo As New RegionInfo(cultureInfo__1.LCID)
If DrpCurrency.Items.FindByValue(regionInfo.ISOCurrencySymbol) Is Nothing Then
DrpCurrency.Items.Add(New ListItem(regionInfo.ISOCurrencySymbol + "" + regionInfo.CurrencySymbol))

End If
Next


Here the output :

curr.png

Answer

Because you need a subset of data you need to build a list of currency symbols and sort that.

Dim currencyList As List(Of String) = New List(Of String)

For Each cultureInfo As CultureInfo In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
    Dim regionInfo As RegionInfo = New RegionInfo(cultureInfo.LCID)
    If Not currencyList.Contains(regionInfo.ISOCurrencySymbol) Then
        currencyList.Add(regionInfo.ISOCurrencySymbol)
    End If        
Next

DropDownList1.DataSource = currencyList.OrderBy(Function(k) k)
DropDownList1.DataBind