You can now declaratively databind any ASP.NET control to
the new RSSDataSource control provided in the toolkit. For example, to build a
simple blog post aggregator for my blog you could follow the below steps with
the free
Visual Web Developer tool:
1) Create a new blank page
Figure 1
<img border=0 width=662 height=445src="/ArticleFiles/919/image001.jpg">
2) Drag/Drop the standard ASP.NET DataList control on the
page, choose the “New DataSource” option from the smart-task:
Figure 2
3) Select the RSSDataSource control to bind to (note: this
will automatically be populated in the datasource dialog window if the
RSSDataSource control has been added to the VS toolbox):
Figure 3
4) In the RSSDataSource dialog that pops-up, type in the URL
to the RSS feed you want to databind to:
Figure 4
5) The RSSDataSource control will then request the schema
for the RSS feed and expose it to VS – which will then populate the
<asp:datalist> control with an <itemTemplate> that
is automatically populated with data-binding expressions for each of
the RSS schema fields from the remote RSS source:
Figure 5
6) You can then switch into template editing mode in the
WYSIWYG designer, or go into source-view to remove some of the fields and just
leave the RSS fields you want to bind to. Here is a sample page with a
DataList template that binds to the link and title RSS item fields:
Listing 1
<%@ Register Assembly="RssToolkit" Namespace="RssToolkit" TagPrefix="RssToolkit"%>
<html>
<head runat="server">
<title>ScottGu Feed</title>
</head>
<body>
<form id="form1"runat="server">
<div>
<h2>ScottGu Blog Feed</h2>
<asp:DataList ID="DataList1"
runat="server" CellPadding="4"
DataSourceID="RssDataSource1" ForeColor="#333333">
<ItemTemplate>
<asp:HyperLink
ID="HyperLink1" runat="server" NavigateUrl='<%#
Eval("link")%>' Text='<%# Eval("title")%>'></asp:HyperLink>
</ItemTemplate>
</asp:DataList>
<RssToolkit:rssdatasource
id="RssDataSource1" runat="server"
url="http://weblogs.asp.net/scottgu/Rss.aspx">
</RssToolkit:rssdatasource>
</div>
</form>
</body>
</html>
7) I can then run the page and get this output:
Figure 6
As you can see above, the DataList is now bound to the data
returned from the remote RSS feed on my site.
What is really cool is that the RSSDataSource control will
cache the RSS data to avoid hitting it remotely on each request – so that you
can efficiently add this type of blog aggregation functionality to your site
and not have to worry about your performance slowing down.