Click here to Skip to main content
15,311,014 members
Articles / Web Development / ASP.NET
Posted 7 Nov 2006


34 bookmarked

How to bind RSS feeds to a GridView

Rate me:
Please Sign up or sign in to vote.
3.57/5 (5 votes)
8 Nov 2006CPOL1 min read
How to bind RSS feeds to a GridView.

Sample Image - GridView_RSS.jpg


RSS-Feeds are great to stay informed about recent changes in your favorite websites. But it is quiet hard to read the XML documents for humans. So, I will show how you can bind RSS feeds (for example, the newest articles on CodeProject) to a GridView.

The GridView

First, create a new aspx file and drop a GridView to the form. Next, turn off "Auto generate fields" from the GridView properties. Last, create a Template field for the hyperlink to the article and a bound field for the description. Here is the code:

 <form id="form1" runat="server">
   <asp:GridView ID="GridView1" runat="server" 
       <asp:TemplateField HeaderText="Title">
          <a href=<%# Eval("link") %> 
            target=_blank><%# Eval("title") %></a>
       <asp:BoundField DataField="description" 
           HeaderText="Description" />

Now, you can copy the code for the GridView as many times you need it. Maybe a GridView for aspalliance as well.

The code behind

Import the namespace System.Data and create the Page_Load event. Then, call the function BindGrid for every RSS-feed you will display on your web page. The function BindGrid needs three parameters:

  • the string pointing to the URL of the news feed
  • the GridView object that will display the news
  • and an integer indicating which part of the feed will be bound
Imports System.Data
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, _
              ByVal e As System.EventArgs) Handles Me.Load
        BindGrid("" & _ 
                 "webservices/articlerss.aspx", _
                 GridView1, 3)
        BindGrid("", _
                 GridView2, 2)
    End Sub
    Sub BindGrid(ByVal strRss As String, ByVal oGrid _
                 As GridView, ByVal iTable As Integer)
        Dim oDs As New DataSet
        oGrid.DataSource = oDs.Tables(iTable)
    End Sub
End Class

BindGrid creates a new DataSet object and reads the feed using ReadXml. Then the XML document is bound to the GridView. You can also find an online example here: How to bind RSS feeds to a GridView.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Germany Germany
Florian works as consultant for change- and configuration management for about 7 years. In this environment he is often forced to work with unix, perl and shell scripts.

For more information about change- and configuration management (espacially Serena Dimensions) visit:

For video tutorials about, ajax, gridviews, ... (in german) visit:

Comments and Discussions

QuestionHow to get only top 2 records Pin
Member 398531517-May-10 21:19
MemberMember 398531517-May-10 21:19 
AnswerRe: How to get only top 2 records Pin
Member 41442081-Oct-10 4:37
MemberMember 41442081-Oct-10 4:37 
GeneralAutoGenerateColumns Pin
MBrooker30-Nov-06 11:02
MemberMBrooker30-Nov-06 11:02 
GeneralNice, concrete article Pin
adrianmurillo15-Nov-06 8:23
Memberadrianmurillo15-Nov-06 8:23 
GeneralRe: Nice, concrete article Pin
fstrahberger15-Nov-06 21:07
Memberfstrahberger15-Nov-06 21:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.