[导入]如何添加RSS和读取RSS


 

WebForm3.aspx

在html 页面中只有这一句哦;
不能有任何HTML标签
None.gif HTML
None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
<% dot.gif @ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="DataGridPage.WebForm3"  %>
None.gif


C#

None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Data.SqlClient;
None.gif
namespace  DataGridPage
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// WebForm3 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class WebForm3 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
InBlock.gif
            if(! this.IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif    
InBlock.gif                SqlConnection conn
=new SqlConnection("Server=.;database=pubs;uid=sa;pwd=;");
InBlock.gif                conn.Open();
InBlock.gif                SqlDataAdapter com
=new SqlDataAdapter("select top 10  * from employee",conn);
InBlock.gif                
InBlock.gif                DataSet ds
=new DataSet();
InBlock.gif                com.Fill(ds);
InBlock.gif                
string strRSS="";
InBlock.gif            
InBlock.gif                strRSS 
= strRSS + "<rss version=\"2.0\"";
InBlock.gif                strRSS 
= strRSS + "<channel>";
InBlock.gif                strRSS 
= strRSS + "<title>*********</title>";
InBlock.gif                strRSS 
= strRSS + "<link>http://www.******/unet</link>";
InBlock.gif                strRSS 
= strRSS + "<language>zh-cn</language> ";
InBlock.gif                strRSS 
= strRSS + "<description>BY UNET</description>";
InBlock.gif        
InBlock.gif                
foreach(DataRow R in ds.Tables[0].Rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    strRSS 
= strRSS+"<item>";
InBlock.gif                    strRSS 
= strRSS + "<title>" +R[1]+ "</title>";
InBlock.gif                    strRSS 
= strRSS + "<link>http://www.****/shownews.aspx?id=" +R[3]+ "</link> ";
InBlock.gif                    strRSS 
= strRSS + "<description>" +R[0]+ "</description>";
InBlock.gif          
InBlock.gif                    strRSS 
= strRSS + "</item>";
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                strRSS 
= strRSS+"</channel>";
InBlock.gif                strRSS
=strRSS+"</rss>";
InBlock.gif                Response.Write(strRSS);    
InBlock.gif                Response.ContentType
="text/xml";
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

下面是读取RSS的方法


     if ( !   this .IsPostBack)
            {
                
string  strURL = " http://localhost/DataGridPage/WebForm3.aspx " ;
                XmlTextReader reader
= new  XmlTextReader(strURL);
                DataSet ds
= new  DataSet();
                ds.ReadXml(reader);
                
this .DataGrid1.DataSource = ds.Tables[ 2 ];
            
//     this.div.InnerHtml=Server.HtmlDecode(ds.Tables[2].Rows[1]["description"].ToString());
                 this .DataGrid1.DataBind();

            }
768624.html

suiqirui 2007-06-02 12:56 发表评论

文章来源: http://www.cnblogs.com/suiqirui19872005/archive/2007/06/02/768624.html

转载于:https://www.cnblogs.com/QiRuiNet-helloworld/archive/2007/06/19/789064.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值