Solved

ASP.net , C# & VB Bind a Yahoo RSS Feed to a Gridview

Posted on 2008-10-17
1
582 Views
Last Modified: 2013-12-17
Hi,
I am trying to get code to read from RSS Feed to a GridView in ASP.Net VB & C#
I looked at the following:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_23438677.html
I have made some alterations to the existing, but am still getting errors.
I have the c# code in App_Code folder CSCode
VB code in App_Code folder VBCode
and referenced the folders in Web.config as follows:
<codeSubDirectories><add directoryName="VBCode"/><add directoryName="CSCode"/>

C# Code First:

using System;

using System.Data;

using System.Data.SqlClient;

using System.Web.Configuration;

using System.Collections;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class rssCS : System.Web.UI.Page

{

 

    protected void Page_Load(object sender, EventArgs e)

    {

        GridView.DataSource = GetDataSet().Tables[3];

        GridView.DataBind();

    }

    private DataSet GetDataSet()

        

    {

        DataSet ds = new DataSet("rsRSS");

        ds.ReadXml("http://rss.news.yahoo.com/rss/mostviewed");

        GridView.DataMember = "item";

        GridView.DataSource = ds;

        //GridView1.DataBind();

        return ds;

    }

 

 

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        GridViewRow row = e.Row;

        DateTime CurrTime = DateTime.Now.Date;

 

        if (row.RowIndex >= 0) // Start looping on the first row

            if (row.RowType == DataControlRowType.DataRow)

            {

                row.Cells[0].Text = row.Cells[0].Text;

                row.Cells[1].Text = row.Cells[1].Text;

            }

 

        }

 

 

}

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="~/App_Code/CSCode/FeedRss.aspx.cs" Inherits="rssCS" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Import Namespace="System.Web.Configuration" %>

<%@ Import Namespace="System.Collections" %>

<%@ Import Namespace="System.Collections.Generic" %>

<%@ Import Namespace="System.Linq" %>

<%@ Import Namespace="System.Web" %>

<%@ Import Namespace="System.Web.UI" %>

<%@ Import Namespace="System.Web.UI.WebControls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>FeedRss</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <asp:GridView

        id="GridView"

        DataSourceId="srcMovies"

        Runat="server" />

        <ItemTemplate>

        <asp:HyperLink ID="HyperLink1" NavigateUrl=<%#DataBinder.Eval(Container.DataItem,"link") %> 

        runat="server">

        <%#DataBinder.Eval(Container.DataItem,"title") %>

        </asp:HyperLink>

        </ItemTemplate>

        </asp:GridView>

<!--

     See TextFile.txt

-->

    <asp:SqlDataSource

        id="srcMovies"

        ConnectionString="Data Source=.\SQLExpress;

            AttachDbFilename=|DataDirectory|MyDatabase.mdf;

            Integrated Security=True;User Instance=True"

        SelectCommand="SELECT * FROM Movies"

        Runat="server" />

    </div>

    </form>

</body>

</html>

VB CODE:

Imports System

Imports System.Data

Imports System.Data.SqlClient

Imports System.Web.Configuration

Imports System.Collections

Imports System.Collections.Generic

Imports System.Linq

Imports System.Web

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Xml

 

Namespace AspNetUnleased.Samples

    Public Class rssVB

        Public Sub New()

 

            Dim myXMLDOC As New XmlDocument()

            myXMLDOC.Load("http://www.builderau.com.au/feeds/features.htm")

 

            Dim xmlNode As System.Xml.XmlNode

            Dim xmllist As XmlNodeList

            xmllist = myXMLDOC.SelectNodes("rss/channel/item")

            For Each xmlNode In xmllist

                Dim titlenode As XmlNode

                Dim linknode As XmlNode

                titlenode = xmlNode.SelectSingleNode("title")

                linknode = xmlNode.SelectSingleNode("link")

                Dim myhyperlink As New HyperLink

                myhyperlink.NavigateUrl = linknode.InnerText

                myhyperlink.Text = titlenode.InnerText & "<br/><br/>"

                myhyperlink.Attributes.Add("style", "color:#336699;font-size:12px;font-family:Arial;a:hover{color:red;background-color:yellow}")

                Dim placeholder1

                placeholder1.Controls.Add(myhyperlink)

            Next

        End Sub

 

    End Class

End Namespace

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="~/App_Code/VBCode/FeedRss.aspx.vb" Inherits="rssVB" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Import Namespace="System.Web.Configuration" %>

<%@ Import Namespace="System.Collections" %>

<%@ Import Namespace="System.Collections.Generic" %>

<%@ Import Namespace="System.Linq" %>

<%@ Import Namespace="System.Web" %>

<%@ Import Namespace="System.Web.UI" %>

<%@ Import Namespace="System.Web.UI.WebControls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>FeedRss</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <asp:GridView

        id="GridView"

        DataSourceId="srcMovies"

        Runat="server" />

        <ItemTemplate>

        <asp:HyperLink ID="HyperLink1" NavigateUrl=<%#DataBinder.Eval(Container.DataItem,"link") %> 

        runat="server">

        <%#DataBinder.Eval(Container.DataItem,"title") %>

        </asp:HyperLink>

        </ItemTemplate>

        </asp:GridView>

<!--

     See TextFile.txt

-->

 

    <asp:SqlDataSource

        id="srcMovies"

        ConnectionString="Data Source=.\SQLExpress;

            AttachDbFilename=|DataDirectory|MyDatabase.mdf;

            Integrated Security=True;User Instance=True"

        SelectCommand="SELECT * FROM Movies"

        Runat="server" />

    </div>

    </form>

</body>

</html>

Open in new window

0
Comment
Question by:homeshopper
1 Comment
 
LVL 13

Accepted Solution

by:
jeebukarthikeyan earned 500 total points
ID: 22775680
hi ,

follow this  link
http://www.codeproject.com/KB/webforms/GridView_RSS.aspx

b u d d h a
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now