排序列表并使用C#在asp.net下拉列表 [英] sorted list and drop down list in asp.net using c#

查看:302
本文介绍了排序列表并使用C#在asp.net下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它返回一个排序列表的方法,我想它的数据源到一个DropDownList。

我用

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

但它提供了一个错误:没有重载方法的containsKey和的containsValue。  如何填充这个排序表中的下拉列表?

解决方案

  DropDownList1.DataSource = stList;
DropDownList1.DataValueField =关键;
DropDownList1.DataTextField =值;
DropDownList1.DataBind();
 

添加测试工作code:

 排序列表< INT,字符串>名单=新的排序列表< INT,字符串>();
list.Add(1,测试1);
list.Add(2的Test2);

dropDownList.DataTextField =值;
dropDownList.DataValueField =关键;
dropDownList.DataSource =清单;
dropDownList.DataBind();
 

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

这篇关于排序列表并使用C#在asp.net下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆