Country List in ASP.NET

Susantaown
Posted by in ASP.NET category on for Beginner level | Views : 29775 red flag
Rating: 2 out of 5  
 1 vote(s)

Its very difficult to remember to all the country name. This article will collect all the country name and bind to a DropDownList.

Its very simple class just import this Country.cs in your application and get all the country name.


 Download source code for Country List in ASP.NET

Introduction

Developing one Customer registration page we need country name most of the time. But its very difficult to remember all the country name and bind it to country dropdown list. This article will help us to get all the country name.

How to use this Country.cs file?


Country.cs is one class file just add to your BAL(Business Access Layer) 
1: Download this Country.cs file.
2: Go to BAL Add Existing Item and select this class


Code of Country.cs file.

CountryNAme

How to Bind the country list to dropdownlist?


.cs file code


I am attaching Country.cs file as well the complete porject how i am using in UI Level please find the attachment.
Page copy protected against web site content infringement by Copyscape

About the Author

Susantaown
Full Name: susant kumar
Member Level: Starter
Member Status: Member
Member Since: 3/5/2009 1:45:33 AM
Country:


MCTS

Login to vote for this post.

Comments or Responses

Posted by: SheoNarayan on: 6/7/2010
Dear Susant,

Thank you for your effort and showing the way to get the list of countries.

Perhaps there is another way to do this and perhaps easier than this, just pass the drop down in below function and it will bind with the list of country. You can modify this code as per your need.

/// <summary>

/// populate country name
/// </summary>
/// <param name="dropDown"></param>
public static void GetCountryNames(DropDownList dropDown)
{
Hashtable h = new Hashtable();

Dictionary<string, string> objDic = new Dictionary<string, string>();
foreach (CultureInfo ObjCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo objRegionInfo = new RegionInfo(ObjCultureInfo.Name);
if (!objDic.ContainsKey(objRegionInfo.EnglishName))
{
objDic.Add(objRegionInfo.EnglishName, objRegionInfo.TwoLetterISORegionName.ToLower());
}
}

SortedList<string, string> sortedList = new SortedList<string, string>(objDic);

foreach (KeyValuePair<string, string> val in sortedList)
{
dropDown.Items.Add(new ListItem(val.Key, val.Key));
}

dropDown.Items.Insert(0, new ListItem("Select", "Select"));
dropDown.Items.Insert(1, new ListItem("Other Country", "Other"));
}


Thank and keep writing Susant.

Best regards
Sheo Narayan

Login to post response

Comment using Facebook(Author doesn't get notification)