C# 使用c在asp.net中创建排序列表和下拉列表#
我有一个返回sortedList的方法,我想将其数据源化为Dropdownlist 我正在使用C# 使用c在asp.net中创建排序列表和下拉列表#,c#,.net,asp.net,generics,data-binding,C#,.net,Asp.net,Generics,Data Binding,我有一个返回sortedList的方法,我想将其数据源化为Dropdownlist 我正在使用 DropDownList1.DataSource=stList; DropDownList1.DataValueField=stList.ContainsValue(); DropDownList1.DataTextField=stList.ContainsKey(); DropDownList1.DataBind(); 但它给出了一个错误:containsKey和containsValue没有重载
DropDownList1.DataSource=stList;
DropDownList1.DataValueField=stList.ContainsValue();
DropDownList1.DataTextField=stList.ContainsKey();
DropDownList1.DataBind();
但它给出了一个错误:containsKey和containsValue没有重载方法。
如何在下拉列表中填充此排序表
Dim SL As New SortedList(Of String, String)
SL.Add("A", "1")
SL.Add("B", "2")
DD1.DataSource = SL
DD1.DataTextField = "key"
DD1.DataValueField = "value"
DD1.DataBind()
[编辑]
添加测试的工作代码:
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();
SortedList=new SortedList();
增加(1,“测试1”);
增加(2,“测试2”);
dropDownList.DataTextField=“Value”;
dropDownList.DataValueField=“Key”;
dropDownList.DataSource=列表;
dropDownList.DataBind();
谢谢。。我使用它,但它会在下拉列表中显示System.Collection.SortedList。它不会出现错误,但会在下拉列表中显示,而不是显示System.Collection中的值。SortedList@user1-我测试了这个代码。用我使用的复制/粘贴代码更新了我的答案,并验证了它是否正常工作。
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();