C# - Dumping a list to a dropdownlist

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

List is populated here, then sorted:



        
6条回答
  •  春和景丽
    2020-12-15 22:48

    ddl.DataSource = nameList; 
    ddl.DataBind(); 
    

    Doesn't work if it's a SharePoint list - Error: Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource. Decided to chime in, in case any SharePoint developers thought this was for an SPList instead of List, as was written above.

    There is a way to bind to an SPList, but you'd use an SPListItemCollection, or go one better and use an SPDataSource. For the SharePoint developers, see this blog by Chris O' Brien.

提交回复
热议问题