在下拉列表中对数据进行排序 [英] Sorting Data in dropdownlist

查看:149
本文介绍了在下拉列表中对数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

object[] SortedItems = new object[DropDownList1.Items.Count];
for (int i = 0; i < SortedItems.Length; i++)
{
SortedItems[i] = DropDownList1.Items[i];
}
Array.Sort(SortedItems);
DropDownList1.Items.Clear();
DropDownList1.Items.AddRange(SortedItems);


在上面的代码中,我将DropDownList中的项目复制到ArrayList,对ArrayList进行了排序,清除了DropDownList.

我无法将已排序的项目添加到DropDownList.

在此先谢谢您.


In the above code I copied items in DropDownList to ArrayList, I sorted the ArrayList, cleared the DropDownList.

I could not add the sorted items to the DropDownList.

Thanks in advance.

推荐答案

请参阅此链接.它将对您有帮助.
使用C#在ASP.NET中排序下拉列表 [ ^ ]
Refer this link. It will help you.
Sorting Dropdown list in ASP.NET using C#[^]


请参阅以下差异链接.解决方案
使用LINQ:
http://www.dotnetcurry.com/ShowArticle. aspx?ID = 312 [^ ]
或solution1或参考
^ ]
或使用ddlId.Sorted = True;如果您要绑定该DDL
Refer following links for diff. solutions
using LINQ:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=312[^]
or solution1 or refer
Sort Method for an ASP.NET DropDownList[^]
or use ddlId.Sorted=True; if u r binding that DDL


,请参阅此链接.
这显示了如何将下拉列表的数据源作为数据库.
http://www.dbtutorials.com/advanced/populatingdropdown-csharp.aspx [ ^ ]


此链接显示了如何对下拉列表中的数据进行排序.
http://abhijitjana.net/2010/08/08/how-to-sort-asp-net-dropdownlist-based-on-datavaluefield-or-datatextfield-using-linq/ [
Refer this links.
This shows how to give dropdown''s datasource as database.
http://www.dbtutorials.com/advanced/populatingdropdown-csharp.aspx[^]


This link shows how to sort data in dropdownlist.
http://abhijitjana.net/2010/08/08/how-to-sort-asp-net-dropdownlist-based-on-datavaluefield-or-datatextfield-using-linq/[^]


Combine these two and write your code.
Hope this helps you.

All the best.


这篇关于在下拉列表中对数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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