C# - Dumping a list to a dropdownlist

前端 未结 6 1623
耶瑟儿~
耶瑟儿~ 2020-12-15 22:09
List nameList = new List();
DropDownList ddl = new DropDownList();

List is populated here, then sorted:



        
6条回答
  •  孤街浪徒
    2020-12-15 22:42

        foreach (string name in nameList){
            ddl.Items.Add(new ListItem(nameList[name].ToString()));
        }
    

    Is your problem.

    it should look more like

    foreach (string name in nameList){
        ddl.Items.Add(new ListItem(name.ToString()));
    }
    

    But I actually like Marcus' suggestion a little better.

提交回复
热议问题