如何在c#中填充不带数据库的DropDown中的状态列表

时间:2014-04-18 12:11:37

标签: c#

我希望在不使用数据库的情况下用状态列表填充下拉列表

我填写了国家/地区下拉列表,其中包含以下代码

 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);
            }

任何人都可以告诉我如何在不使用数据库的情况下获取州名单

3 个答案:

答案 0 :(得分:4)

    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");

答案 1 :(得分:1)

或者另一种选择是从web service here获取列表{/ 3}}

答案 2 :(得分:0)

您好试试这将填写没有数据库的国家

  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;