ASP.NET的TreeView排序 [英] ASP.NET TreeView sort
问题描述
我习惯的WinForm TreeView控件
其具有自动管理节点排序一个排序
属性。
我现在必须按字母顺序排序的ASP.NET TreeView控件
,我很惊讶,我找不到任何类似的属性或回调方法。
I am accustomed to winform TreeView
having a Sorted
property which automatically manages nodes sorting.
I now have to alphabetically sort an ASP.NET TreeView
and I'm surprised I cannot find any similar property or callback method.
有没有什么办法来自动实现ASP.NET这个操作还是我不得不手动排序和插入我的节点以正确的顺序?
Is there any way to automatically achieve this operation in ASP.NET or do I have to manually sort and insert my nodes in correct order?
推荐答案
您需要编写自己的排序功能,但其合理的琐碎添加此功能。
You'll need to write your own sorting function but its reasonably trivial to add this functionality.
的http:// blog.mdk-photo.com/post/C-Extentionmethod-Tree-Node-View-Sort().aspx
.NET 3.5支持扩展方法,这样你就可以以pre-现有系统类添加功能。注意的方法的参数这种
语法。 <一href=\"http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx\"相对=nofollow>更多信息这里
.NET 3.5 supports extension methods so you can add functionality to pre-existing System Classes. Notice the this
syntax on the method parameter. More Info Here
public static void Sort(this TreeView tv)
{
TreeNodeCollection T = tv.Nodes.Sort();
tv.Nodes.Clear();
tv.Nodes.AddRange(T);
}
public static void Sort(this TreeNode tn)
{
TreeNodeCollection T = tn.ChildNodes.Sort();
tn.ChildNodes.Clear();
tn.ChildNodes.AddRange(T);
}
第一个链接包含$ C $其余c您将需要完成排序功能
The first link contains the rest of the code you'll need to complete the sorting functionality
这篇关于ASP.NET的TreeView排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!