Background
There is often a need to display a county list. For that many beginners and developers use a database to store the list of countries and they are displayed using a specific control but by using this method there are many server resources used that results in the application becoming slow and it is not be possible to display all the countries of the world exactly.
But by using the Globalization class of C# you can easily do it without any database or without using many server resources, so by considering the above requirement I have written this article for beginners, students and anyone that wants to learn. So let us start from the basics.
The 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 that support those cultures/locales.
- Writing code that functions equally well in any of the supported cultures/locales.
- using System.Globalization;
I hope you understand some basics about the Globalization class.
Now let us start to create a Website as:
- Open Visual Studio from Start -> All programs -> Microsoft Visual Studio.
- Then go to to "File" -> "New" -> "WebSite..." then select Visual C# -> Web application.
- Then specify the name, CountryList, or any name as you wish and the location of the project and click on the OK button. The new web site is created.
Use the following source code in the default.aspx <body> section page as:
- <body>
- <form id="form1" runat="server">
- <div class="div" align="center">
- <br /> <br />
- <asp:DropDownList ID="DropDownList1" runat="server" Width="100px">
- </asp:DropDownList>
- </div>
- </form>
- </body>
Then switch to view code and create the following method in the default.aspx.cs to get the country list using Globalization:

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

In the code above I first ensured that my page is not posted back using the IsPostBack property so the dropdownlist is not be refreshed every page post-back and then I just assigned the country list method to the dropdownlist Data Source property and finally calling the Data Bind method to bind the dropdownlist. You can also bind the preceding list method to any control that supports the Data Source property.
Now run the application and select a Country from the DropDownList that looks as in the following image:

From the preceding example, it's clear that if we undersatnd the .Net Framework deeply then you can reduce our application code more than, or at least, 50 percent and that results in better application performance.

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

In the code above I first ensured that my page is not posted back using the IsPostBack property so the dropdownlist is not be refreshed every page post-back and then I just assigned the country list method to the dropdownlist Data Source property and finally calling the Data Bind method to bind the dropdownlist. You can also bind the preceding list method to any control that supports the Data Source property.
Now run the application and select a Country from the DropDownList that looks as in the following image:

From the preceding example, it's clear that if we undersatnd the .Net Framework deeply then you can reduce our application code more than, or at least, 50 percent and that results in better application performance.
Note:
- For detailed code please download the Zip file attached above.
Summary
From all the examples above we see how to reduce the code required to do 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.


Omar MallatPosted Jun 13, 2022, 9:56 AM EDT
Did you notice that this list is not accurate. for example, the GetCulture command return Cyprus with LCID 4096, but when you create the RegionInfo of 4096, it returns Djibouti!!!!
Hasan HabibPosted Jan 9, 2017, 10:17 PM EST
Did anyone have code for full list of countries not using retrieve from database table?
Vithal WadjeTOP 100Posted Mar 17, 2016, 12:06 AM EDT
refer my other articles
Chioma JoshuaPosted Mar 16, 2016, 7:25 AM EDT
Hello.. Thank You For Sharing... i want to also get a list of states and cities in each country..
Vithal WadjeTOP 100Posted Nov 12, 2014, 4:46 AM EST
thanks Nattharee Pisarnsathukit
Vithal WadjeTOP 100Posted Nov 12, 2014, 4:44 AM EST
yes venkat kumar sir,soon i will post article
Venkat KumarPosted Nov 12, 2014, 1:31 AM EST
Nice.. but i just want to get the state names based on selected Country and then City name based on state.. ?
Vithal WadjeTOP 100Posted Sep 23, 2014, 6:20 AM EDT
thanks sir
Abhijit PatilPosted Sep 22, 2014, 9:59 PM EDT
Great artical sir
Sunny SharmaPosted Sep 22, 2014, 2:40 AM EDT
Nice%20article!%20You're%20getting%20the%20countries%20in%20list%20but%20the%20Globalization%20class%20doesn't%20mean%20to%20provide%20with%20the%20country%20names.%20If%20you%20closely%20count%20the%20items%20in%20drop%20down%20list%20-%20they%20will%20count%20to%20140%20only%2C%20and%20you%20see%20we%20have%20more%20than%20140%20countries%20in%20the%20world.%20Globalization%20class%20provides%20culture%20information%20for%20most%20of%20the%20countries%2C%20not%20all.%20So%2C%20one%20should%20never%20rely%20on%20CultureInfo%20for%20getting%20the%20country%20list%2C%20it%20will%20fail.
Nattharee PisarnsathukitPosted Sep 22, 2014, 1:12 AM EDT
Thank you! Good for using
nivethitha thangavelPosted May 30, 2014, 10:55 PM EDT
very good work sir, and i want to know how to do this for selecting state and city
Vithal WadjeTOP 100Posted Mar 7, 2014, 9:25 AM EST
sure sir,i will check it
ilaya bharathiPosted Mar 7, 2014, 12:19 AM EST
sir output is getting but when i try to submit the county in db it default taking Afghanistan even i select the country its taking the 1st value only could you please check it that
ilaya bharathiPosted Mar 7, 2014, 12:00 AM EST
great but pakistan is missing
Vithal WadjeTOP 100Posted Oct 18, 2013, 10:20 AM EDT
thanks Sahil Sharma sir,i will look and update you soon
Sahil SharmaPosted Oct 18, 2013, 4:22 AM EDT
Very Useful..but there is a strange issue as Pakistan is not showing in the list
Vithal WadjeTOP 100Posted Jul 27, 2013, 10:05 AM EDT
thanks alok
alok ranjanPosted Jul 27, 2013, 7:49 AM EDT
it is superb for my project thanks
Vithal WadjeTOP 100Posted Jul 4, 2013, 10:10 PM EDT
thanks priya
priya talolePosted Jul 4, 2013, 12:51 AM EDT
Its working sir superb artical it is useful for me thank you
Vithal WadjeTOP 100Posted Jul 3, 2013, 6:57 AM EDT
Miracle cant I say yes but I am trying for that,thanks
MiraclePosted Jul 3, 2013, 1:02 AM EDT
is it possible to display city of the country and province?