Wednesday, November 2, 2011

CultureInfo Class - populate the dropdownlist with countries using culture in asp.net with vb

in Default.aspx.vb

Imports System.Globalization
Imports System.Collections.Generic



 Public Function getcountry() As List(Of String)
        Dim list As New List(Of String)()
        Dim culture As CultureInfo() = CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures Or CultureTypes.SpecificCultures)

        For Each info As CultureInfo In Culture
            Dim info2 As New RegionInfo(info.LCID)
            If Not List.Contains(info2.EnglishName) Then
                List.Add(info2.EnglishName)
                List.Add(info2.DisplayName)

            End If

        Next
        Return List
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      DropDownList1.DataSource = getcountry()

        DropDownList1.DataBind()
         DropDownList1.Items.Insert(0, "select")



    End Sub

No comments:

Post a Comment