使用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(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |