ARTICLE

CultureInfo class in VB.NET

Posted by Rohatash Kumar Articles | ASP.NET using VB.NET August 11, 2011
The CultureInfo class contains culture-specific information, such as the language, country/region, calendar, and cultural conventions.
 
Reader Level:

CultureInfo class

 

The CultureInfo class from the System.Globalization namespace. The CultureInfo class contains culture-specific information, such as the language, country/region, calendar, and cultural conventions.  The CultureInfo class specifies a unique name for each culture.  you can set the Culture property of the page, like this:

<%@ Page Language="vb" Culture="en-US" %>

If you run the example now, you will get the output "English (United States)", which is the language of English, with a specific US culture.

 

GetCultures method

 

GetCultures method to retrieve a complete list of all cultures.

 

.ASPX code

 

Now taking a DropDownList control on the form.

 

<div>

        <span><strong>Select Country :</strong></span>&nbsp;&nbsp;

        <asp:DropDownList ID="ddl" runat="server" BackColor="#3399FF"

            ForeColor="#66FF66">

        </asp:DropDownList>

    </div>

 

Now call this GetCountry method on your page load that will bind and display countries in the DropDownList.

 

Imports System.Globalization

Public Class WebForm1

    Inherits System.Web.UI.Page

 

    Public Function GetCountry() As List(Of String)

 

        Dim list As New List(Of String)()

        Dim cultures As CultureInfo() = CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures Or CultureTypes.SpecificCultures)

        For Each info As CultureInfo In cultures

            Dim info2 As New RegionInfo(info.LCID)

            If Not list.Contains(info2.EnglishName) Then

                list.Add(info2.EnglishName)

            End If

        Next

        Return list

    End Function

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

        ddl.DataSource = GetCountry()

        ddl.DataBind()

        ddl.Items.Insert(0, "Select")

    End Sub

End Class

 


Now run the application and test it. This will show all the country that are bind with DropDownList.


ddl2.gif

 

Figure1

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor