开发者

sorted list and drop down list in asp.net using c#

开发者 https://www.devze.com 2023-03-07 02:51 出处:网络
I have an method which returns a sortedList and i want to datasource it to a Dropdownlist. i am using

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()
0

精彩评论

暂无评论...
验证码 换一张
取 消