开发者

How to order a list

I have a function in sitefinity that returns a list of categories.

//return list of categories
    private IList<ICategory> GetCategoryDataSou开发者_如何转开发rce() {

        var cntManager = new ContentManager(CaseStudyManager.DefaultContentProvider);
        IList allCategories = cntManager.GetCategories();
        List<ICategory> filteredList = new List<ICategory>();
        foreach (ICategory category in allCategories) {

            filteredList.Add(category);

        }
        return filteredList;
    }

What I want to know is how to sort this list.

Categories in Sitefinity are as far as i can tell just a string, there are no other fields associated with a category. Therefore I have nothing to sort the categories on, other than appending each category with a number, like:

1 - Legal
2 - Financial
3 - Property

When these categories are displayed on the website I can then at least trim the parts i need.

Can anyone help with the sorting though?

Thanks Al


Use IComparer Interface


If you name them like you mentioned, with a prefix, you can do this:

001|xxxxxxx

002|djskdjskd

003|sdkdsajdaks

foreach (ICategory category in allCategories) 
{              
    filteredList.Add(category.SubString(4);          
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜