Wednesday, 3 July 2013

Country List Dropdown without DataBase in C#

By using the Globalization class of C# you can easily do it without any database or without using lots of server resources.So let us start from basics.

What is Globalization class ?

According to MSDN, Globalization is the process of designing and developing a software product that functions in multiple cultures/locales. 

This process involves:
Identifying the culture/locale that must be supported Designing features which support those cultures/locales.
Writing code that functions equally well in any of the supported cultures/locales.
You can use the Globalization class by using the Namespace
using System.Globalization;
For more details about Globalization class you can refer the MSDN site.

I hope you understand some basic about the  Globalization class.

Now let us start to create a ASP.Net Project:

Use the following source code in the default.aspx <content> section page as:

<div class="div" align="center">
    <br /> <br />
        <asp:DropDownList ID="DropDownList1" runat="server" Width="100px">

 Then switch to view code and Create the following method in the default.aspx.cs to get country list using Globalization:

        public static List<string> CountryList()
            //Creating list
            List<string> CultureList = new List<string>();

            //getting  the specific  CultureInfo from CultureInfo class
       CultureInfo[] getCultureInfo = CultureInfo.GetCultures(CultureTypes.SpecificCultures);

            foreach (CultureInfo getCulture in getCultureInfo)
                //creating the object of RegionInfo class
                RegionInfo GetRegionInfo = new RegionInfo(getCulture.LCID);
                //adding each county Name into the arraylist
                if (!(CultureList.Contains(GetRegionInfo.EnglishName)))
            //sorting array by using sort method to get countries in order
            //returning country list
            return CultureList;

Now call the above method on page load with dropdonlist to bind the country list as

        protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
                DropDownList1.DataSource = CountryList();
 In the above code first I have ensure that my page is not post back by using the IsPostBack property so dropdownlist can not be refreshed every page post back and after that I have just assigned the country list method to the dropdownlist Data Source property and finally calling Data Bind method to bind dropdownlist  also you can bind the above list method to any control which supports Data Source property.

Now run the application and select a Country from the DropDownList which looks as in the following image:

From the above example ,its clear that if we undersatnd .Net Framework deeply you can reduce our application code more than or atleast  50 percent which results application performance faster.

For detailed code please download the zip file attached Download this Article.

From all the examples above we see how to reduce the code required to perform these tasks. I hope this article is useful for all students and beginners. If you have any suggestion related to this article then please contact me


  1. K then How to do this for states also.....

  2. how to get states while selecting countries in dropdown list



ADFS (1) ADO .Net (2) Ajax (1) Angular (1) Angular Js (17) Angular2 (28) ASP .Net (14) Authentication (1) Azure (1) Breeze.js (1) C# (50) CD (1) CI (2) CloudComputing (1) CMS (1) CSS (2) Design_Pattern (3) DevOps (4) DI (4) Dotnet (22) Entity Framework (3) ExpressJS (4) Html (3) IIS (1) Javascript (6) Jquery (8) Lamda (3) Linq (11) Mongodb (1) MVC (50) NodeJS (7) RDLC (1) Report (1) SDLC (1) Sql Server (30) SSIS (3) SSO (1) SSRS (2) UI (1) WCF (13) Web Api (11) Web Service (1) XMl (1)