Vinit Patel

Display news in iframe

Posted on: October 26, 2009


In The News.aspx Page

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”News.aspx.cs” Inherits=”News” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head runat=”server”>
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:GridView ID=”gvNews” runat=”server” AutoGenerateColumns=”false” ShowHeader=”false”>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID=”mylink” runat=”server” Text='<%# Eval(“Title”) %>’ NavigateUrl='<%# “~/NewsDetails.aspx?nid=” + DataBinder.Eval(Container, “RowIndex”) %>’></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

Codebehind in News.aspx page,

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;

public partial class News : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Gets the xml from the Url using XmlTextReader
XmlTextReader reader = new XmlTextReader(“http://www.rediff.com/rss/newsrss.xml&#8221;);
// creates a new instance of DataSet
DataSet ds = new DataSet();
// Reads the xml into the dataset
ds.ReadXml(reader);
// Assigns the data table to the datagrid
gvNews.DataSource = ds.Tables[3];
// Binds the datagrid
gvNews.DataBind();
}
}
}

In NewsDetails.aspx Page,

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”NewsDetails.aspx.cs” Inherits=”NewsDetails” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head runat=”server”>
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<iframe id=”myiframe” runat=”server” width=”100%” height=”600px”></iframe>
</div>
</form>
</body>
</html>

In Codebehind of NewsDetails.aspx page,

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;

public partial class NewsDetails : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString[“nid”] != null)
{
// Gets the xml from the Url using XmlTextReader
XmlTextReader reader = new XmlTextReader(“http://www.rediff.com/rss/newsrss.xml&#8221;);
// creates a new instance of DataSet
DataSet ds = new DataSet();
// Reads the xml into the dataset
ds.ReadXml(reader);

Int32 index = 0;
Int32.TryParse(Request.QueryString[“nid”].ToString(), out index);
string link = ds.Tables[3].Rows[index][“link”].ToString();

myiframe.Attributes.Add(“src”, link);
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Calendar

October 2009
M T W T F S S
« Sep   Dec »
 1234
567891011
12131415161718
19202122232425
262728293031  

Stats Of Blog

  • 6,962 hits

Cluster Map

%d bloggers like this: