Sorted list and dropdown in asp.net using C #

I have a method that returns sortedList, and I want to pass it to the unpack list.

I use

DropDownList1.DataSource=stList;
DropDownList1.DataValueField=stList.ContainsValue();
DropDownList1.DataTextField=stList.ContainsKey();
DropDownList1.DataBind();

But this gives an error: there is no overload method for containsKey and containsValue. How to fill this sorted table in the drop down list?

+3
source share
3 answers
DropDownList1.DataSource = stList;
DropDownList1.DataValueField = "Key";
DropDownList1.DataTextField = "Value";
DropDownList1.DataBind();

[change]

Adding test 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();
+10
source
    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()
+2
source

-1

All Articles