Home > ASP.Net > Get and Bind all Countries to DropdownList Using Globalization

Get and Bind all Countries to DropdownList Using Globalization


Hi all,

Try this example to Get and Bind all Countries to Dropdownlist Using Globalization

Select Country:

<asp:DropDownList ID="ddlcountry" runat="server"> </asp:DropDownList>

In Code behind :


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetAllCountry();
}
}

public void GetAllCountry()
{
try
{
List<string> listcountry = new List<string>();
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
foreach (CultureInfo cinfo in cultures)
{
RegionInfo Rinfo = new RegionInfo(cinfo.LCID);
if (!listcountry.Contains(Rinfo.EnglishName))
{
listcountry.Add(Rinfo.EnglishName);
}
}
listcountry.Sort();
ddlcountry.DataSource = listcountry;
ddlcountry.DataBind();
ddlcountry.Items.Insert(0, new ListItem("--Select Country--", "0"));
}
catch (Exception ex)
{
}
}

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: