Look at the effect first:
First you need an ascx page to bind the content of the RSS feed to a ListView through a XDocument. The code is as follows:
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
For demo purposes.
System.Threading.Thread.Sleep (1000);
XDocument Feedxml =
Xdocument.load ("http://feeds.feedsky.com/csdn.net/dujingjing1230");
var feeds = from Feed in feedxml.descendants ("item")
Select New
{
Title = feed. Element ("title"). Value,
Link = feed. Element ("link"). Value,
Description = feed. Element ("description"). Value
};
Postlist.datasource = feeds;
Postlist.databind ();
}
Copy Code code as follows:
<asp:listview runat= "Server" id= "Postlist" >
<LayoutTemplate>
<ul>
<asp:placeholder runat= "Server" id= "Itemplaceholder"/>
</ul>
</LayoutTemplate>
<ItemTemplate>
<li><a href= ' <%# eval ("Link")%> ' ><%# Eval ("Title")%></a><br/>
<%# Eval ("Description")%>
</li>
</ItemTemplate>
</asp:ListView>
Next you need to create an ASPX page to display the RSS content, and of course this page uses jquery ajax to get the data.
HTML page code:
AJAX functionality to achieve the JS:
Copy Code code as follows:
$ (document). Ready (function () {
$.ajax ({
Type: "POST",
URL: "Rssreader.asmx/getrssreader",
Data: "{}",
ContentType: "Application/json; Charset=utf-8 ",
DataType: "JSON",
Success:function (msg) {
$ (' #RSSContent '). Removeclass (' loading ');
$ (' #RSSContent '). HTML (MSG.D);
}
});
});
Finally, the content of this Web services is rssreader.asmx:
Copy Code code as follows:
public class RSSReader:System.Web.Services.WebService {
[WebMethod]
public string Getrssreader ()
{
Page page = new page ();
UserControl ctl =
(UserControl) page. LoadControl ("~/rssreadercontrol.ascx");
Page. Controls.Add (CTL);
StringWriter writer = new StringWriter ();
HttpContext.Current.Server.Execute (page, writer, false);
return writer. ToString ();
}
}
The page is also useful to a picture is not uploaded here.
Code Download:
Http://xiazai.jb51.net/200909/yuanma/RSSREader.rar