Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList1.DataSource = GetCountry();
        DropDownList1.DataBind();
        DropDownList1.Items.Insert(0, "Select");
    }

        public List<string> GetCountry()
    {
        List<string> list = new List<string>();
       CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures | CultureTypes.SpecificCultures);
       // CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
        foreach (CultureInfo info in cultures)
        {
            RegionInfo info2 = new RegionInfo(info.LCID);
            if (!list.Contains(info2.EnglishName))
            {
                list.Add(info2.EnglishName);
            }
        }
 
        return list;


I tried this code but i got error:There is no region associated with the Invariant Culture (Culture ID: 0x7F).plz help me?
Posted
Updated 29-Apr-16 21:42pm
v2

try this

C#
public static List<string> getCountryList()
{
List<string> list= new List<string>();
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.SpecificCultures);
foreach (CultureInfo info in cultures)
{
if (culture.LCID != 127)
{
RegionInfo info2= new RegionInfo(info.LCID);

if (!(list.Contains(info2.EnglishName)))
{
list.Add(info2.EnglishName);
}
}
}
list.Sort(); 
return list;
}
 
Share this answer
 
Add this check too

if (culture.LCID != 127 && !culture.IsNeutralCulture)
{
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900