A simple RSS example

Source: Internet
Author: User

Testrss. aspx:

<% @
Page
Language = "C #"
Autoeventwireup = "true"
Contenttype = "text/XML"
Codebehind = "testrss. aspx. cs"
Inherits = "namespace1.testrss"
%>


<Asp: Repeater
Id = "repeater1"
Runat = "server">


<Headertemplate>


<RSS
Version = "2.0">


<Channel>


<Title> ASP. NET news! </Title>


<Link> http://www.ASPNETNews.com/Headlines/ </link>


<Description>

This is the syndication feed for aspnetnews.com.


</Description>


</Headertemplate>


<Itemtemplate>


<Item>


<Title> <% # formatforxml (databinder. eval (container. dataitem,


"Title") %> </title>


<Description>


<% # Formatforxml (databinder. eval (container. dataitem,


"Description") %>


</Description>


<Link>

Http://www.ASPNETNews.com/Story.aspx? Id = <% #


Databinder. eval (container. dataitem, "ArticleID") %>


</Link>


<Author> <% # formatforxml (databinder. eval (container. dataitem,


"Author") %> </author>


<Pubdate>


<% #
String. Format ("{0: R }",


Databinder. eval (container. dataitem,


"Datepublished") %>


</Pubdate>


</Item>


</Itemtemplate>


<Footertemplate>


</Channel>


</RSS>


</Footertemplate>


</ASP: repeater>

 

Testrss3.aspx. Designer. CS:

Namespace namespace1 {

 

 


///
<Summary>


/// Testrss class.


///
</Summary>


///
<Remarks>


/// Auto-generated class.


///
</Remarks>


Public
Partial
Class
Testrss {

 


///
<Summary>


/// Repeater1 control.


///
</Summary>


///
<Remarks>


/// Auto-generated field.


/// To modify move field declaration from designer file to code-behind file.


///
</Remarks>


Protected
Global: system. Web. UI. webcontrols. Repeater repeater1;

}

}

 

Testrss. aspx. CS:

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;

 

Namespace namespace1

{


Public
Partial
Class
Testrss: system. Web. UI. Page

{


Protected
Void page_load (Object sender, eventargs E)

{

Repeater1.datasource = getdataset ();

Repeater1.databind ();

}

 


Private
Dataset getdataset ()

{


Dataset1 dataset1 = new
Dataset1 ();


Datarow ROW = dataset1.tables [0]. newrow ();

Row ["title"] = "title1 ";

Row ["author"] = "author1 ";

Row ["Description"] = "description1 ";

Row ["datepublished"] = datetime. now;

Dataset1.tables [0]. Rows. Add (ROW );

 

Row = dataset1.tables [0]. newrow ();

Row ["title"] = "title2 ";

Row ["author"] = "author2 ";

Row ["Description"] = "description2 ";

Row ["datepublished"] = datetime. now;

Dataset1.tables [0]. Rows. Add (ROW );

 


Return dataset1;

}

 


Protected
String formatforxml (Object input)

{


String data = input. tostring (); // cast the input to a string

 


// Replace those characters disallowed in XML documents

Data = data. Replace ("&", "& amp ;");

Data = data. Replace ("\" "," & quot ;");

Data = data. Replace ("'", "& apos ;");

Data = data. Replace ("<", "& lt ;");

Data = data. Replace (">", "& gt ;");

 


Return data;

}

 

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.