国家显示名称和代码的下拉列表

时间:2011-12-27 02:30:45

标签: c# asp.net

有人可以向我展示一个示例或教程,显示国家及其代码的下拉列表 我的代码显示错误的新西兰语言代码显示mi-NZ而不是en-NZ

ASP.NET

protected void Page_Load(object sender, EventArgs e)     {

    SortedDictionary<string, string> objDic = 
           new SortedDictionary<string, string>();                     

    foreach (CultureInfo ObjectCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))         
    {            
        RegionInfo objRegionInfo = new RegionInfo(ObjectCultureInfo.Name);             
        if(!objDic.ContainsKey(objRegionInfo.EnglishName)) {                     
            objDic.Add(objRegionInfo.EnglishName, ObjectCultureInfo.Name); 
        }         
    }

    foreach (KeyValuePair<string, string> val in objDic)
    {              
        ddlCountries.Items.Add(new ListItem(val.Key, val.Value));         
    }   

}

e.g

United States(en-US)
New Zealand(en-NZ)
China(zh-CN)

1 个答案:

答案 0 :(得分:3)

您要排除RegionInfo.EnglishName,删除!并尝试CultureTypes.AllCultures

foreach (CultureInfo ObjectCultureInfo in CultureInfo.GetCultures(CultureTypes.AllCultures))         
{            
    RegionInfo objRegionInfo = new RegionInfo(ObjectCultureInfo.Name); 
    if(objDic.ContainsKey(objRegionInfo.EnglishName)) {                     
        objDic.Add(objRegionInfo.EnglishName, ObjectCultureInfo.Name); 
    } 
}