如何添加RSS和读取RSS


 

WebForm3.aspx

在html 页面中只有这一句哦;
不能有任何HTML标签
HTML


<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="DataGridPage.WebForm3" %>


C#

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace DataGridPage
{
    
/// <summary>
    
/// WebForm3 的摘要说明。
    
/// </summary>

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


                }


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


            }


        
Web 窗体设计器生成的代码
    }

}

下面是读取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();

            }
posted @ 2007-06-02 12:56  过河卒A  阅读(2255)  评论(1编辑  收藏  举报