Tuesday, July 7, 2009

Selecting unique node in a RSS feed base on user selection using c# asp.net

Selecting unique node in a RSS feed base on user selection using  c# asp.net

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default10.aspx.cs" Inherits="Default10" %>
<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="bank" Runat="server" DataSourceID="xds" AutoGenerateColumns="false" AllowPaging="True"  >
<Columns>

<asp:TemplateField>   
<ItemTemplate>       
<%# Container.DataItemIndex + 1 %>   
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
       <a href='Default10.aspx?url1=<%# Container.DataItemIndex + 1 %>'  >
          <%#XPath("title")%></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:XmlDataSource ID="xds" Runat="server" DataFile="http://rss.news.yahoo.com/rss/topstories"
>
</asp:XmlDataSource>
   
    </div>
    </form>
</body>
</html>

code behind

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default10 : System.Web.UI.Page
{
    string strURL;
    protected void Page_Load(object sender, EventArgs e)
    {
       // Response.Write(Request["url1"].ToString());

        if (Request["url1"] == null)
        {
            xds.XPath = "rss/channel/item [position()>=0]";
            //strURL = "1";
        }
        else
        {
            //xds.XPath = "rss/channel/item [position()=" + Request["url"] + "]";
            strURL = Request["url1"];
            xds.XPath = "rss/channel/item [position()=" + strURL + "]";
        }

       

    }
}

No comments: