Friday, January 22, 2010

Using RSS Feed in Your Website


I am going to explain the process of using RSS Feeds in the following steps


Step 1. First Create a new website oropen existing website in which you want to use/ read RSS Feed

Step 2. Then, Create/ open .aspx page where you want to show the data using RSS Feed.

Step 3. Then, drag the XMLData source component from Toolbox under  Data tab-> to the page.
Step 4. Configure the Datasource of XMLDataSource 
            Provide the Url of Feed in DataFile Field and following line 'rss/channel/item' in XPath Field or you can provide these two field from properties of XMLDataSource too.
Step 5. Drag DataList to your page and choose Datasource to XMLDataSource1 (Id of XMLDataSource).
Step 5. Paste the following code in the in the html source view between Item Template of DataList

                <asp:LinkButton ID="lbtnLink" runat="server" PostBackUrl='<%#XPath("link")%>' Text='<%#XPath("title")%>'></asp:LinkButton>
                <hr color="#0099ff" />
                <br />
                <%#XPath("description")%>
                <hr color="#ccaa33" />
                <br />
                <%#XPath("pubDate")%><br />  


 Now All set and run the page to view the output.




Here is the html source view of the above written steps


        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://timesofindia.indiatimes.com/rssfeedsdefault.cms"
            XPath="rss/channel/item"></asp:XmlDataSource>       
        <br />
        <asp:DataList ID="DataList1" runat="server" BackColor="Green" BorderColor="#DEDFDE" CellPadding="3"
            BorderWidth="1px" DataSourceID="XmlDataSource1"
            ForeColor="Black" GridLines="Vertical">

            <ItemTemplate>
                <asp:LinkButton ID="lbtnLink" runat="server" PostBackUrl='<%#XPath("link")%>' Text='<%#XPath("title")%>'></asp:LinkButton>
                <hr color="#0099ff" />
                <br />
                <%#XPath("description")%>
                <hr color="#ccaa33" />
                <br />
                <%#XPath("pubDate")%><br />
            </ItemTemplate>
        </asp:DataList>   

No comments:

Post a Comment