0
我想按某個XML元素對列表視圖進行排序。如何對綁定到XML數據源的ListView進行排序
這裏是我的aspx代碼顯示列表視圖是如何設置的:
<asp:ListView ID="ListView1" runat="server" DataSourceID="newsDataSource">
<LayoutTemplate>
<div id="ItemPlaceHolderContainer" runat="server">
<span id="ItemPlaceHolder" runat="server" />
</div>
</LayoutTemplate>
<ItemTemplate>
<h2><%# XPath("title") %></h2>
<p><%# XPath("contents") %></p>
<p>Author: <%# XPath("author") %></p>
<p>Date Time: <%# XPath("datetime") %></p>
</ItemTemplate>
</asp:ListView>
<asp:XmlDataSource ID="myDataSource" runat="server" DataFile="~/Data.xml">
</asp:XmlDataSource>
這裏是XML的例子:
<?xml version="1.0" encoding="utf-8"?>
<theNews>
<news>
<title>Welcome!</title>
<contents>Hello, and welcome!</contents>
<author>Me</author>
<datetime>6/11/2014 4:40:35 PM</datetime>
</news>
</theNews>
我想要做的是排序的內容ListView根據'datetime'XML元素。任何人都知道我可以做到這一點?
protected void Page_Load(object sender, EventArgs e)
{
// TODO: Sort me here!!
}