...Technology Simplified

Friday, June 8, 2012

How to display rss feed in asp.net

No comments :
In this post I will show you how to display rss feed in asp.net using XmlDataSource and DataList control.
Create a web page name it as RSSFeed.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtUrl" runat="server" Width="349px"></asp:TextBox>
<asp:Button ID="btnLoad" runat="server" Text="Load" OnClick="btnLoad_Click" />
<asp:DataList ID="dlRss" runat="server">
<ItemTemplate>
<%#XPath("title") %>
<i>
<%#XPath("description") %></i> <i>
<%#XPath("pubdate") %></i> <b><a href="<%#XPath("link") %>">
<%#XPath("link") %></a></b>
</ItemTemplate>
</asp:DataList>
<asp:XmlDataSource ID="xml" runat="server" XPath="rss/channel/item"></asp:XmlDataSource>
</div>
</form>
</body>
</html>
protected void btnLoad_Click(object sender, EventArgs e)
{
if (txtUrl.Text != "")
{
xml.DataFile = txtUrl.Text;
dlRss.DataSourceID = xml.ClientID;
}
}

No comments :

Post a Comment