Let's take a look at the effect:
First, you need an ascx page to bind the content of the RSS source to a listview through an xdocument.CodeAs follows:
Copy code The Code is 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 the Code the code is as follows:
<% # eval ("title") %>
<% # eval ("Description ") %>
Create An ASPX page to display the RSS content. Of course, jquery Ajax is used on this page to obtain the above data.
HTML page code:
JS that implements Ajax: copy Code the code is 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');
contents ('{rsscontent'{.html (MSG. d);
}< BR >});
});
Finally, the content of rssreader. asmx Web Services is as follows:Copy codeThe Code is 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 also uses an image and will not be uploaded here.
Download Code:
Http://xiazai.jb51.net/200909/yuanma/RSSREader.rar