我的asp.net 2.0 rsss顯示

來源:互聯網
上載者:User
   學.net有一段時間了,也做了些小東西。現在看起來幼稚的很。很長時間沒有熬過夜了,還有些不習慣。今天晚上,在搞rss的xml資料顯示。也希望和大家交流交流。可自訂要顯示的xml文檔地址,和顯示的記錄數
源碼: 示範地址http://shiyan3-1.at.vwdhosting.net/   所有源碼:下載

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
public partial class rss : System.Web.UI.UserControl
{
    private string url1="rss/1.xml";
    private int sl1=10;
    protected void Page_Load(object sender, EventArgs e)
    {
        XmlDocument xml1 = new XmlDocument();
        xml1.Load(Server.MapPath(url1));
        XmlNodeList kk = xml1.DocumentElement.ChildNodes[0].SelectNodes("item");
        Label1.Text = "<ul style='margin-left:15px;'>";
        for (int k = 0; k < sl1; k++)
        {
            string ss = "";
            if (kk.Item(k).ChildNodes[0].InnerText.Length >= 30)
            {
                ss = kk.Item(k).ChildNodes[0].InnerText.Substring(0, 30);
            }
            else
            {
                ss = kk.Item(k).ChildNodes[0].InnerText;
            }
          
            Label1.Text += "<li><a href=" + kk.Item(k).ChildNodes[1].InnerText +  " title='"+kk.Item(k).ChildNodes[0].InnerText+"'>" + ss + "</a></li>";
        }

        Label1.Text += "<ul>";
    }
    public string url
    {
        set
        {
            url1 = value;
        }
    }
    public int sl
    {
        set
        {
            sl1 = value;
        }
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.