How to display rss feed in

In this post I will show you how to display rss feed in using XmlDataSource and DataList control. Rss_cs.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RSS_CS.aspx.cs" Inherits="RSS_CS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:TextBox ID="txtUrl" runat="server" Width="349px"></asp:TextBox>
        <asp:Button ID="btnLoad" runat="server" Text="Load" OnClick="btnLoad_Click" />
        <br />
        <asp:DataList ID="dlRss" runat="server">
                <%#XPath("title") %><br />
                    <%#XPath("description") %></i> <i>
                        <br />
                        <%#XPath("pubdate") %></i> <b><a href='<%#XPath("link") %>'>
                            <%#XPath("link") %></a></b><br />
        <asp:XmlDataSource ID="xml" runat="server" XPath="rss/channel/item"></asp:XmlDataSource>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class RSS_CS : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void btnLoad_Click(object sender, EventArgs e)
        if (txtUrl.Text != "")
            xml.DataFile = txtUrl.Text;
            dlRss.DataSourceID = xml.ClientID;

No comments:

Post a Comment