如何在没有c#数据库的情况下填写DropDown中的状态列表
本文关键字:DropDown 列表 状态 情况下 数据库 | 更新日期: 2023-09-27 17:58:58
Ii想在不使用数据库的情况下用状态列表填充下拉列表
我用以下代码填写了国家/地区下拉列表
RegionInfo Countries = new RegionInfo(new CultureInfo("en-us",false).LCID);
List<string> CountryNames = new List<string>();
foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
Countries = new RegionInfo(new CultureInfo(cul.Name,false).LCID);
CountryNames.Add(Countries.DisplayName.ToString());
}
IEnumerable CountryNamesAdded = CountryNames.OrderBy(names => names).Distinct();
foreach (string items in CountryNamesAdded)
{
DrdCountryList.Items.Add(items);
}
有人能告诉我如何在不使用数据库的情况下获得无状态列表吗
Dictionary<string, string> states = new Dictionary<string, string>();
states.Add("AL", "Alabama");
states.Add("AK", "Alaska");
states.Add("AZ", "Arizona");
states.Add("AR", "Arkansas");
states.Add("CA", "California");
states.Add("CO", "Colorado");
states.Add("CT", "Connecticut");
states.Add("DE", "Delaware");
states.Add("DC", "District of Columbia");
states.Add("FL", "Florida");
states.Add("GA", "Georgia");
states.Add("HI", "Hawaii");
states.Add("ID", "Idaho");
states.Add("IL", "Illinois");
states.Add("IN", "Indiana");
states.Add("IA", "Iowa");
states.Add("KS", "Kansas");
states.Add("KY", "Kentucky");
states.Add("LA", "Louisiana");
states.Add("ME", "Maine");
states.Add("MD", "Maryland");
states.Add("MA", "Massachusetts");
states.Add("MI", "Michigan");
states.Add("MN", "Minnesota");
states.Add("MS", "Mississippi");
states.Add("MO", "Missouri");
states.Add("MT", "Montana");
states.Add("NE", "Nebraska");
states.Add("NV", "Nevada");
states.Add("NH", "New Hampshire");
states.Add("NJ", "New Jersey");
states.Add("NM", "New Mexico");
states.Add("NY", "New York");
states.Add("NC", "North Carolina");
states.Add("ND", "North Dakota");
states.Add("OH", "Ohio");
states.Add("OK", "Oklahoma");
states.Add("OR", "Oregon");
states.Add("PA", "Pennsylvania");
states.Add("RI", "Rhode Island");
states.Add("SC", "South Carolina");
states.Add("SD", "South Dakota");
states.Add("TN", "Tennessee");
states.Add("TX", "Texas");
states.Add("UT", "Utah");
states.Add("VT", "Vermont");
states.Add("VA", "Virginia");
states.Add("WA", "Washington");
states.Add("WV", "West Virginia");
states.Add("WI", "Wisconsin");
states.Add("WY", "Wyoming");
或者另一个选项是从这里提到的web服务获取列表
嗨,试试这个这将填充没有数据库的国家
List<string> objcountries = new List<string>();
CultureInfo[] objculture = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
foreach (CultureInfo getculture in objculture)
{
RegionInfo objregion = new RegionInfo(getculture.LCID);
string ss = getculture.DisplayName;
if (!(objcountries.Contains(objregion.EnglishName)))
{
objcountries.Add(objregion.EnglishName);
}
}
objcountries.Sort();
comboBox1.DataSource = objcountries;