listview数据绑定的字母顺序
本文关键字:顺序 数据绑定 listview | 更新日期: 2023-09-27 18:24:59
我需要订购我的类别标题-
(<%#Eval("类别描述").ToString().ToUpper()%>)
按字母顺序排列。我该怎么做?谢谢
以下是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();
}
在代码隐藏文件的顶部添加using System.Linq;
,然后将数据源分配更改为:
lstvwFileCategory.DataSource = fls.GetHAHADocument_Categories((int)PageID)
.OrderBy(c => c.CategoryDescription);