【问题标题】:listview databind alphabetical orderlistview 数据绑定字母顺序
【发布时间】:2013-07-25 14:58:31
【问题描述】:

我需要订购我的类别标题 -

( )

按字母顺序。我该怎么做呢?谢谢!

下面是 C# 中的代码:

    protected void lstvwFileCategory_OnItemDataBound(Object sender,   
    ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            ListViewDataItem temp = (ListViewDataItem)e.Item;
            Files.HAHADocument_Category catdata =   
            (Files.HAHADocument_Category)temp.DataItem;

            ListView files = new ListView();
            files = (ListView)e.Item.FindControl("lstvwFiles");

            files.DataSource = catdata.Documents;
            files.DataBind();
        }
     }

这是代码本身:

     <asp:ListView runat="server" ID="lstvwFileCategory"  
     OnItemDataBound="lstvwFileCategory_OnItemDataBound">
          <LayoutTemplate>
              <asp:Literal runat="server" ID="itemPlaceholder" />
          </LayoutTemplate>
          <ItemTemplate>
               <div class="linksection">
                    <h2><%#Eval("CategoryDescription").ToString().ToUpper()%></h2>
                    <asp:ListView runat="server" ID="lstvwFiles"  
                    OnItemDataBound="lstdvwFiles_OnItemDataBound">
                         <LayoutTemplate>
                             <asp:Literal runat="server" ID="itemPlaceholder" />
                         </LayoutTemplate>
               </div>
          </ItemTemplate>
     </asp:ListView>

 if (PageID > 0)
    {
        HAHA_BLL.FileRepository.Files fls = new HAHA_BLL.FileRepository.Files();
        lstvwFileCategory.DataSource =  
        fls.GetHAHADocument_Categories((int)PageID);
        lstvwFileCategory.DataBind();
    }

【问题讨论】:

  • 你能贴出填充lstvwFileCategory的代码吗?
  • 如果我有 Apples 和 Oranges,目前它正在查看 Oranges 的 ID 为 23,Apples 的 ID 为 498。所以顺序颠倒了。我只需要它来查看第一个字母并按字母顺序排列。

标签: c# listview data-binding alphabetical


【解决方案1】:

在代码隐藏文件的顶部添加using System.Linq;,然后将数据源分配更改为:

lstvwFileCategory.DataSource = fls.GetHAHADocument_Categories((int)PageID)
                                    .OrderBy(c => c.CategoryDescription);

【讨论】:

    猜你喜欢
    • 2021-12-08
    • 2019-01-23
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-09
    相关资源
    最近更新 更多