I had a question from a friend of mine at work, he's using the DataList with the XmlDataSource. He wanted to get the Top X records fro the XML file to show them in the DataList, so here is a simple way of doing so I found after doing some search online:
XMLDataSrouce:
<asp:XmlDataSource DataFile=Path to XML File" ID="XmlDataSource1"
runat="server" XPath="rss/channel/item[position() < 11]">
As you can see, we are retrieving the TOP 10 Records from the XML file by using the POSITION() method to get less than 11 records, which is 10 or less records.
The DataList is a simple one:
<asp:datalist id="DataList1" runat="server" datasourceid="XmlDataSource1">
<itemtemplate>
<a href="<%# XPath("link") %>"><%# XPath("title") %></a>
</itemtemplate>
</asp:datalist>
We are binding the DataList to the XmlDataSource and displaying the links retrieved.
Hope this helps,
Regards
Tags: ASP.NET 2.0 - General