熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET長文章分頁顯示函數

2022-06-13   來源: .NET編程 

  public string NoHTML(string Htmlstring) //去除HTML標記
    {
        //刪除腳本
        Htmlstring = RegexReplace(Htmlstring @ <script[^>]*?>*? </script> RegexOptionsIgnoreCase);
        //刪除HTML
        Htmlstring = RegexReplace(Htmlstring @ <([^>]*)> RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @([\r\n])[\s]+ RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @> RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @ <!* RegexOptionsIgnoreCase);

  Htmlstring = RegexReplace(Htmlstring @&(quot|#); \ RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @&(amp|#); & RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @&(lt|#); < RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @&(gt|#); > RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @&(nbsp|#); RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @&(iexcl|#); \xa RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @&(cent|#); \xa RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @&(pound|#); \xa RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @&(copy|#); \xa RegexOptionsIgnoreCase);
        Htmlstring = RegexReplace(Htmlstring @&#(\d+); RegexOptionsIgnoreCase);

  HtmlstringReplace( < );
        HtmlstringReplace(> );
        HtmlstringReplace(\r\n );
        Htmlstring = HttpContextCurrentServerHtmlEncode(Htmlstring)Trim();

  return Htmlstring;
    }
  public string OutputBySize(string p_strContent)//分頁函數
    {
        string m_strRet = ;
        int m_intPageSize = ;//文章每頁大小
        int m_intCurrentPage = ;//設置第一頁為初始頁
        int m_intTotalPage = ;
        int m_intArticlelength = NoHTML(p_strContent)Length;//文章長度
        if (m_intPageSize < m_intArticlelength)
        {//如果每頁大小大於文章長度時就不用分頁了
            if (m_intArticlelength % m_intPageSize == )
            {//set total pages count
                m_intTotalPage = m_intArticlelength / m_intPageSize;
            }
            else
            {//if the totalsize
                m_intTotalPage = m_intArticlelength / m_intPageSize + ;
            }
            if (RequestQueryString[pages] != null)
            {//set Current page number
                try
                {//處理不正常的地址欄的值
                    m_intCurrentPage = ConvertToInt(RequestQueryString[pages]);
                    if (m_intCurrentPage > m_intTotalPage)

  m_intCurrentPage = m_intTotalPage;

  }

  catch
                {
                    m_intCurrentPage = m_intCurrentPage;
                }
            }
            //set the page content 設置獲取當前頁的大小
            if (m_intCurrentPage < m_intTotalPage)
            {
                m_intPageSize = m_intCurrentPage < m_intTotalPage ? m_intPageSize : (m_intArticlelength m_intPageSize * (m_intCurrentPage ));
                m_strRet += p_strContentSubstring(m_intPageSize * (m_intCurrentPage ) m_intPageSize);
            }
            else if(m_intCurrentPage == m_intTotalPage )
            {
                int mm_intPageSize=m_intArticlelength m_intPageSize * (m_intCurrentPage );
                m_strRet += p_strContentSubstring(m_intArticlelength mm_intPageSize);
            }

  string m_strPageInfo = <p> </p>;
            for (int i = ; i <= m_intTotalPage; i++)
            {
                if (i == m_intCurrentPage)
                    m_strPageInfo += + i + 頁 | ;
                else
                    m_strPageInfo += <a + RequestQueryString[wzid] + _pages + i + l> + i + </a>|;
            }
            //輸出顯示各個頁碼
            thislabPageNumberText = m_strPageInfo;

  }
        else
        {
            m_strRet += p_strContent;
        }
        return m_strRet;
    }

  protected void Page_Load(object sender EventArgs e)
    {
  SqlDataReader dr = shujuduquzt(IntParse(RequestQueryString[wzid]));
        if (dr == null) return;
        if (drRead())
        {
            thislabContentText = OutputBySize(dr[wzcontent]ToString());//調用該函數

  前台頁面分頁處使用的控件 <asp:Label ID=labPageNumber    FontSize=px runat=server> </asp:Label>


From:http://tw.wingwit.com/Article/program/net/201311/12101.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.