I have an method which returns a sortedList and i want to datasource it to a 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. How to popu开发者_运维百科late 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()
精彩评论