加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用c#在asp.net中排序列表和下拉列表

发布时间:2020-12-15 23:59:03 所属栏目:百科 来源:网络整理
导读:我有一个方法,它返回一个sortedList,我想将它数据源到Dropdownlist. 我在用 DropDownList1.DataSource=stList;DropDownList1.DataValueField=stList.ContainsValue();DropDownList1.DataTextField=stList.ContainsKey();DropDownList1.DataBind(); 但它给出
我有一个方法,它返回一个sortedList,我想将它数据源到Dropdownlist.

我在用

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

但它给出了一个错误:containsKey和containsValue没有重载方法.
?如何在下拉列表中填充此已排序的表?

解决方法

DropDownList1.DataSource = stList;
DropDownList1.DataValueField = "Key";
DropDownList1.DataTextField = "Value";
DropDownList1.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();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读