首页 > 代码库 > RSS

RSS

前台:

  

<?xml version="1.0"?>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RSS.aspx.cs" Inherits="RSS" ContentType="text/xml" %>

<rss version="2.0">
<channel>
<title>XXX网站书店</title>
<description></description>
<link>http://www.bookshop.com</link>
<language>zh-cn</language>
<docs></docs>
<ttl>5</ttl>

<asp:Repeater runat="server" ID="RepeaterRss">
<ItemTemplate>
<item>
<title><%#Eval("Title") %></title>
<link><%#Eval("Id","http://localhost:8088/BookDetail.aspx?id={0}") %></link>
<pubDate><%#Eval("PublishDate") %></pubDate>
<source>XXX网站书店</source>
<author><%#Eval("Author") %></author>
<description><![CDATA[<%#Eval("ContentDescription") %>]]></description>
</item>
</ItemTemplate>
</asp:Repeater>


</channel>
</rss>

 

 

后台:

public partial class RSS : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    LoadRssData();
  }

  private void LoadRssData()
  {
    List<Books> lst = new List<Books>();
    for (int i = 0; i < 15; i++)
    {
       lst.Add(new Books() { Id=i+1, Title="标题"+(i+1), Author="秋月光璇", ContentDescription="详细内容:"+Guid.NewGuid().ToString(), PublishDate=DateTime.Now});
    }
    this.RepeaterRss.DataSource = lst;
    this.RepeaterRss.DataBind();
  }

}

 

 

public class Books
{
  public Books()
  { }

  public int Id { get; set; }
  public string Title { get; set; }
  public string Author { get; set; }
  public DateTime PublishDate { get; set; }
  public string ContentDescription { get; set; }
}

 

RSS