【问题标题】:How to order a list如何订购清单
【发布时间】:2011-02-25 21:24:54
【问题描述】:

我在 sitefinity 中有一个返回类别列表的函数。

//return list of categories
    private IList<ICategory> GetCategoryDataSource() {

        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;
    }

我想知道的是如何对这个列表进行排序。

据我所知,Sitefinity 中的类别只是一个字符串,没有与类别关联的其他字段。因此,除了为每个类别附加一个数字之外,我没有什么可以对类别进行排序的,例如:

1 - Legal
2 - Financial
3 - Property

当这些类别显示在网站上时,我至少可以修剪我需要的部分。

有人可以帮忙排序吗?

谢谢 铝

【问题讨论】:

  • 这不能回答您的问题,但您可以删除您的 foreach / add 语句并将其替换为:filteredList.AddRange(allCategories)
  • ICategory 接口中没有其他属性?没有可以使用的 Id 或 CategoryId? return filteredList.OrderBy(x =&gt; x.CategoryId).ToList()

标签: c# asp.net linq sitefinity


【解决方案1】:

【讨论】:

    【解决方案2】:

    如果你像你提到的那样命名它们,加上前缀,你可以这样做:

    001|xxxxxxx

    002|djskdjskd

    003|sdkdsajdaks

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 2020-09-08
      相关资源
      最近更新 更多