[英]sorted list and drop down list in asp.net using c#
I have an method which returns a sortedList and i want to datasource it to a Dropdownlist. 我有一个方法,它返回一个sortedList,我想将它数据源到Dropdownlist。
i am using 我在用
DropDownList1.DataSource=stList;
DropDownList1.DataValueField=stList.ContainsValue();
DropDownList1.DataTextField=stList.ContainsKey();
DropDownList1.DataBind();
But it gives an error: No overload method for containsKey and containsValue. 但它给出了一个错误:containsKey和containsValue没有重载方法。 How to populate this sorted table in drop down list? 如何在下拉列表中填充此已排序的表?
DropDownList1.DataSource = stList;
DropDownList1.DataValueField = "Key";
DropDownList1.DataTextField = "Value";
DropDownList1.DataBind();
[Edit] [编辑]
Adding tested working code: 添加测试的工作代码:
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();
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.