How to get list of all countries and bind to a dropdown list in ASP.NET

Create an ASP.NET application and add a DropDownList to the page something like this.

  1. <asp:DropDownList ID="ddlCountry" runat="server"></asp:DropDownList>

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

  1. public List<string> GetCountryList()
  2. {
  3. List<string> list = new List<string>();
  4. CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures |
  5. CultureTypes.SpecificCultures);
  6. foreach (CultureInfo info in cultures)
  7. {
  8. RegionInfo info2 = new RegionInfo(info.LCID);
  9. if (!list.Contains(info2.EnglishName))
  10. {
  11. list.Add(info2.EnglishName);
  12. }
  13. }
  14. return list;
  15. }
  16. ddlLocation.DataSource = GetCountryList();
  17. ddlLocation.DataBind();
  18. ddlLocation.Items.Insert(0, "Select");

Note: Updated attachement contains code for orderby the list using LINQ.

Next >> Bind Countries to a DropDownList in ASP.NET