use*_*er1 3 .net c# asp.net generics data-binding
我有一个方法,它返回一个sortedList,我想将它数据源到Dropdownlist.
我在用
DropDownList1.DataSource=stList;
DropDownList1.DataValueField=stList.ContainsValue();
DropDownList1.DataTextField=stList.ContainsKey();
DropDownList1.DataBind();
Run Code Online (Sandbox Code Playgroud)
但它给出了一个错误:containsKey和containsValue没有重载方法.如何在下拉列表中填充此已排序的表?
Ale*_*Aza 10
DropDownList1.DataSource = stList;
DropDownList1.DataValueField = "Key";
DropDownList1.DataTextField = "Value";
DropDownList1.DataBind();
Run Code Online (Sandbox Code Playgroud)
[编辑]
添加测试的工作代码:
SortedList<int, string> list = new SortedList<int, string>();
list.Add(1, "Test1");
list.Add(2, "Test2");
dropDownList.DataTextField = "Value";
dropDownList.DataValueField = "Key";
dropDownList.DataSource = list;
dropDownList.DataBind();
Run Code Online (Sandbox Code Playgroud)