The next version of Visual Studio will bring all kinds of new goodies. One is .NET 3.5 (maybe 4.0 by then) which will include two new controls for ASP.NET developers, the ListView and DataPager controls. My first look at these controls had a few errors, but I quickly go the idea. Here is the example I tried, which simply reads my RSS feed from http://blog.silverlightcity.com and displays the items.
The first step is to create the web form and then drag a DataPager control and the ListView control followed by another DataPager control. I configured the ListView control to use an XMLDataSource which I set the DataFile property to my RSS feed and the xpath property to "/rss/channel/item". That is all that is required for the data source to read all the items in my RSS feed.
The next step is to set the layouttemplate and the item tempate for the Listview control. The layouttemplate specifies the overall look where the items will be embedded. Think of the layouttemplate as a master page (nothing to do with a master page, but functions like one as far as the ListView is concerned by specifying the look of the control) and the itemtemplate as the formatted content that will be inserted into the area specified in the layouttemplate. The itemtemplate governs the appearance of items and the layout dictates the look of the container that holds the items. Here is the code for the ListView:
<asp:ListView ID="ListView1" runat="server" DataSourceID="XmlTheFeed" ItemContainerID="DataSection" >
<layouttemplate>
<br /><br />We are here:<br /><br />
<div id="DataSection" runat="server"></div>
</layouttemplate>
<itemtemplate>
<h2><a href='<%# XPath("link") %>'><%# XPath("title") %></a></h2>
<p><em>Published <%#XPath("pubDate")%></em></p>
<p><%# XPath("description") %></p>
<br />
</itemtemplate>
<ItemSeparatorTemplate>
<div style="height:0px;border-top:dashed 1px #ff0000"></div>
</ItemSeparatorTemplate>
</asp:ListView>
<asp:XmlDataSource ID="XmlTheFeed" runat="server" DataFile="http://blog.silverlightcity.com/Rss.aspx"
XPath="/rss/channel/item"></asp:XmlDataSource>
Notice the use of the "DataSection" label. It is first used in the "ItemContainerID" property of the ListView and then again as the ID of the div I made in the layouttemplate section. Also notice the div mentioned, is set to RunAt="Server". This is what specifies "where" the list of items will appear. In this example, all items will be inserted into the div that has the "DataSection" ID. So, you can see the layouttemplate for the control is a type of skin and the ItemContainerID property of the control specifies the control where the items are to be inserted. Be sure the control where you want the items inserted is flagged to runat="Server".
With the above code on a page, you should be able to display the RSS feed. If there is an error make sure the register line was generated at the top of the page:
<%@ Register assembly="System.Web.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.WebControls" tagprefix="asp" %>
Okay, at this point we are running great and the feed lists out like we desired. Now it is time to hook up those two DataPagers we dropped on the page above and below the ListView control.I set the other pager to the same values and that gives me the paging navigation at the top and bottom of the page. Both can work on the ListView at the same time.
The first step is to set the property "PagedControlID" to the ID of the control we wish this pager to page the data. In our case we set it to "ListVIew1". While there I set the PageSize property to "5".
The next step is to select the type of display you wish for the pager. You can select one of two default types (using the arrow on the DataPager control in design view to select it our build the list of fields by hand. Here is what the pager would look like in code:
<asp:DataPager runat="server" PagedControlID="ListView1" PageSize="5">
<fields><asp:nextpreviouspagerfield ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" /><asp:numericpagerfield />
<asp:nextpreviouspagerfield ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False"
ShowPreviousPageButton="False" />
</fields>
</asp:DataPager>
Well, that is pretty much it. It is not too much work and you can have paged data in a list!
--- Update ---
After a bit of browsing, I found that the ListView has a number of features, including the ability to use groups giving you a more tiled look (or however you configure it) and edit abilities. There is more info on this at:
http://blogs.msdn.com/kashif/archive/2007/ 01/30/listview-presentation-slides-and-samples.aspx
The big major drawback to using these controls on a Interent based site is SEO issues. Since the controls work on postbacks and not url parameters, we are still stuck in the same situation where search engines will not be able to index the pages of data. Since the DataPage is an individual component though, maybe in the future we will see a SEO DataPager that will add this functionality.
Another issue as is with most ASP.NET default server controls is the size of the ViewState. Oh well, there are still ways around that!