C # Ajax Practice VS2005 + Rsstoolkit Develop your own RSS online Reader _c# Tutorials

Source: Internet
Author: User
Tags eval
RSS is a format for describing and synchronizing web content, and is currently the most widely used XML application. RSS builds a technology platform for the rapid dissemination of information, making everyone a potential provider of information. Once an RSS file is published, the information contained in this RSS feed can be invoked directly by other sites and can be used in other terminals and services because the data are standard XML formats.





In the past, if we wanted to implement RSS subscriptions for blogs, we usually needed handwritten code to produce or read XML. Now with the Rsstoolkit, it's all going to be easy. You can use it in five minutes to implement your own RSS feed online reader. This article will describe how to read Web Rss information.





Development environment: VS2005 + Rsstoolkit





First, we need to build a asp.net ajax site





Second, the introduction of Rsstoolkit to the project, the project is as follows (CSS and picture files can be used in my compressed document)








Three, you can start writing code.


1. First you need a ScriptManager, a UpdatePanel, a updateprogress. Haha, it's all nonsense Ajax page programs probably all need these. The rest is what you asked for. The specific page code is as follows:


1 <%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>


2


3 <%@ Register assembly= "Rsstoolkit" namespace= "Rsstoolkit" tagprefix= "Rss"%>


4 <! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >


5 <html xmlns= "http://www.w3.org/1999/xhtml" >


6 <head runat= "Server" >


7 <title> to East Blog reader |meil.livebaby.cn</title>


8 <link href= "Css/layout.css" rel= "stylesheet" type= "Text/css"/>


9


<script language= "JavaScript" type= "Text/javascript" >


one var ls;


The function ls_onclk (itemnumber) {


13


if (ls = = null) ls = $get ("List0");


15


Ls.classname = "";


ls = $get ("list" + ItemNumber);


Ls.classname = "current";


return true;


20}


</script>


22


</head>


<body>


<form id= "Form1" runat= "Server" >


<asp:scriptmanager id= "ScriptManager1" runat= "Server"/>


<div id= "Content-header" >


<h1><asp:hyperlink id= "HyperLink1" runat= "Server" text= "to East" target= "_blank" navigateurl= "http://me" Il.livebaby.cn/index.html "></asp:HyperLink>


29 Blog Reader </h1>


</div>


<div id= "Content-container" >


<div id= "Content-side1" >


<ul class= "List-of-links" >


<li id= "list0" class= "Current" >


<asp:linkbutton id= "lb0" runat= "server" commandargument= "0" onclientclick= "ls_onclk (0);" oncommand= "Lnk_cmd" > Eastward blog </asp:LinkButton></li>


<li id= "List1" >


Notoginseng <asp:linkbutton id= "LB1" runat= "Server" commandargument= "1" onclientclick= "LS_ONCLK (1);" oncommand= "Lnk_cmd" > Financial blog </asp:LinkButton></li>


<li id= "List2" >


<asp:linkbutton id= "LB2" runat= "Server" commandargument= "2" onclientclick= "LS_ONCLK (2);" Oncommand= "Lnk_cmd" >flower blog </asp:LinkButton></li>


<li id= "List3" >


<asp:linkbutton id= "LB3" runat= "Server" commandargument= "3" onclientclick= "LS_ONCLK (3);" oncommand= "Lnk_cmd" > Dynamic Baby Blog </asp:LinkButton></li>


<li id= "List4" >


<asp:linkbutton id= "LB4" runat= "Server" commandargument= "4" onclientclick= "LS_ONCLK (4);" oncommand= "Lnk_cmd" > Yo baby's blog </asp:LinkButton></li>


<li id= "List5" >


<asp:linkbutton id= "LB5" runat= "Server" commandargument= "5" onclientclick= "LS_ONCLK" (5); " Oncommand= "Lnk_cmd" ><font color= "Red" > to the East Blog Park blog </font></asp:LinkButton></li>


<li id= "Li6" >


<asp:linkbutton id= "LB6" runat= "Server" commandargument= "6" onclientclick= "LS_ONCLK (6);" Oncommand= "Lnk_cmd" ><font color= "Red" > Blog Park </font></asp:LinkButton></li>


</ul>


</div>


<div id= "Content-main" >


Wuyi <asp:updatepanel id= "Updatemain" runat= "server" updatemode= "conditional" >


<Triggers>


<asp:asyncpostbacktrigger controlid= "Lb0"/>


<asp:asyncpostbacktrigger controlid= "LB1"/>


<asp:asyncpostbacktrigger controlid= "Lb2"/>


<asp:asyncpostbacktrigger controlid= "Lb3"/>


<asp:asyncpostbacktrigger controlid= "Lb4"/>


<asp:asyncpostbacktrigger controlid= "Lb5"/>


<asp:asyncpostbacktrigger controlid= "Lb6"/>


</Triggers>


<ContentTemplate>


<h2><asp:label id= "Lblheader" runat= "Server" > Latest log </asp:Label></h2>


/> <hr


<asp:panel id= "Pnlblog" runat= "Server" >


<rss:rssdatasource id= "Rssds" runat= "server" maxitems= "0" url= "" ></rss:rssdatasour Ce>


<asp:datalist id= "Lsblog" runat= "Server" datasourceid= "Rssds" >


<ItemTemplate>


<asp:panel id= "Panelheader" runat= "style=" cursor:pointer; Color: #d61719; width:100%; Display:block; " >


<span style= "Float:left;" ><%# Eval ("title")%></span>


<asp:image id= "Image1" runat= "Server" style= "float:right;" Imageurl= "~/images/expand_blue.jpg"/>


</asp:Panel>


<asp:panel id= "Panel1" runat= "Server style=" margin-top:3px;width:100%; Background:transparent URL (images/blogback.gif) no-repeat Text-top left; >


<%# Eval ("description")%>


<asp:hyperlink id= "Hlmore" runat= "server" Navigateurl= ' <%# Eval ("link") %> ' target= "_blank" text= "more Content" ></asp:HyperLink>)


</asp:Panel>


<ajaxt:collapsiblepanelextender id= "Cpe1" runat= "Server" targetcontrolid= "Panel1" "


Expandcontrolid= "Panelheader" collapsecontrolid= "Panelheader" suppresspostback= "True"


Imagecontrolid= "Image1" collapsed= "true" expandedimage= "~/images/collapse_blue. jpg


Collapsedimage= "~/images/expand_blue.jpg"/>


<hr style= "border-bottom:1px dotted #B2B2B2; margin:0px; "/>


Bayi </ItemTemplate>


</asp:DataList>


</asp:Panel>


</ContentTemplate>


</asp:UpdatePanel>


</div>


</div>


<asp:updateprogress id= "UpdateProgress1" runat= "server" displayafter= "0" dynamiclayout= "true" >


<ProgressTemplate>


<div id= "Updprogress" >


<img alt= "" src= "Images/indicator.gif"/>


<span> Data Acquisition </span>


</div>


</ProgressTemplate>


</asp:UpdateProgress>


</form>


<center><div><a href= "http://meil.livebaby.cn" >meil.livebaby.cn</a> procedure: Eastward 2007.7</ Center>


</body>


</html>


100


It is more important that these two parts:


Row 66:<rss:rssdatasource id= "Rssds" runat= "server" maxitems= "0" url= "" ></Rss:RssDataSource>


This is the realization of the core of RSS reading, with this tag to achieve half of the RSS read work, the rest of the?





Looking at the following section, the Lnk_cmd command implements the RSS data binding so that you can access multiple RSS addresses in real time. If you think this is not flexible enough, you can add a textbox and then use the program to bind, which is also good. However, this is not the realization of this, interested friends can try, should not be difficult. Ha ha!





Copy Code code as follows:



Row 35:<asp:linkbutton id= "lb0" runat= "server" commandargument= "0" onclientclick= "ls_onclk (0);"


oncommand= "Lnk_cmd" > Eastward blog </asp:LinkButton></li>


1 protected void Lnk_cmd (object sender, CommandEventArgs e)


2 {


3 int command = Convert.ToInt32 (e.commandargument);


4


5 rssdatabind (command);


6}


Rssdatabind is the binding function, and the code is:


1 protected void rssdatabind (int cmd)


2 {


3 Switch (CMD)


4 {


5 Case 0:


6 Rssds.url = "Http://www.livebaby.cn/blog/u/meil/rss2.xml";


7 Lsblog.databind ();


8 Lblheader.text = "To the East blog";


9 break;


Case 1:


One rssds.url = "Http://www.livebaby.cn/blog/u/money/rss2.xml";


Lsblog.databind ();


Lblheader.text = "financial blog";


break;


Case 2:


Rssds.url = "Http://www.livebaby.cn/blog/u/flower/rss2.xml";


Lsblog.databind ();


Lblheader.text = "Flower Blog";


break;


Case 3:


Rssds.url = "http://www.livebaby.cn/blog/rss2.asp";


Lsblog.databind ();


Lblheader.text = "Dynamic Baby blog Network";


break;


Case 4:


Rssds.url = "Http://www.livebaby.cn/blog/u/yoyo/rss2.xml";


Lsblog.databind ();


Lblheader.text = "Leisurely baby's blog";


break;


Case 5:


Rssds.url = "Http://www.cnblogs.com/meil/rss";


Lsblog.databind ();


Lblheader.text = "To the East Blog Park Blog";


The break;


Case 6:


Rssds.url = "Http://www.cnblogs.com/rss";


Panax Notoginseng lsblog.databind ();


Lblheader.text = "Blog Park";


The break;


Default:


a break;


42}


43}


It's that simple.


Rssds.url = "Http://www.livebaby.cn/blog/u/meil/rss2.xml";


Lsblog.databind ();


Is it just like the binding of DB data. Ms Things, although the structure is not good, but the start is really fast.


How many case is needed depends on what you need. I am here to bind six RSS addresses, you can also more, but should be aware of the page and the number of LinkButton on the corresponding.





The final C # code is as follows:


Copy Code code as follows:



1 protected void rssdatabind (int cmd)


2 {


3 Switch (CMD)


4 {


5 Case 0:


6 Rssds.url = "Http://www.livebaby.cn/blog/u/meil/rss2.xml";


7 Lsblog.databind ();


8 Lblheader.text = "To the East blog";


9 break;


Case 1:


One rssds.url = "Http://www.livebaby.cn/blog/u/money/rss2.xml";


Lsblog.databind ();


Lblheader.text = "financial blog";


break;


Case 2:


Rssds.url = "Http://www.livebaby.cn/blog/u/flower/rss2.xml";


Lsblog.databind ();


Lblheader.text = "Flower Blog";


break;


Case 3:


Rssds.url = "http://www.livebaby.cn/blog/rss2.asp";


Lsblog.databind ();


Lblheader.text = "Dynamic Baby blog Network";


break;


Case 4:


Rssds.url = "Http://www.livebaby.cn/blog/u/yoyo/rss2.xml";


Lsblog.databind ();


Lblheader.text = "Leisurely baby's blog";


break;


Case 5:


Rssds.url = "Http://www.cnblogs.com/meil/rss";


Lsblog.databind ();


Lblheader.text = "To the East Blog Park Blog";


The break;


Case 6:


Rssds.url = "Http://www.cnblogs.com/rss";


Panax Notoginseng lsblog.databind ();


Lblheader.text = "Blog Park";


The break;


Default:


a break;


42}


43}








SOURCE Download Address: Http://www.cnblogs.com/Files/meil/ReaderRss_src.rar


This article permanent address: http://www.livebaby.cn/blog/u/meil/archives/2007/1169.html





Related Article

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.