欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net使用FCK編輯器中的分頁符實現(xiàn)長文章分頁功能

 更新時間:2024年07月01日 12:04:29   作者:smartsmile2012  
這篇文章主要介紹了asp.net使用FCK編輯器中的分頁符實現(xiàn)長文章分頁功能,涉及asp.net字符串及分頁操作的相關(guān)技巧,需要的朋友可以參考下

本文實例講述了asp.net使用FCK編輯器中的分頁符實現(xiàn)長文章分頁功能。分享給大家供大家參考,具體如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SplitContent.aspx.cs" Inherits="SplitContent" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  </div>
  <asp:Panel ID="pnlPage" runat="server" Height="286px">
    <asp:Label ID="ltlContent" runat="server" Text="ltlContent"></asp:Label>
    <br />
    <asp:Label ID="ltlPage" runat="server" Text="ltlPage"></asp:Label>
  </asp:Panel>
  </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class SplitContent : System.Web.UI.Page
{
  private static string a = "123456";
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!IsPostBack)
    {
      //文章分頁頁碼
      int currentPage = Request["cpage"] == null ? 1 : Convert.ToInt32(Request["cpage"]);
      //URL地址
      string pageUrl = Request.Url.ToString();
      ArticlePage(a, currentPage, pageUrl);
    }
  }
  /// <summary>
  ///文章分頁函數(shù)
  /// </summary>
  /// <param name="content">文章內(nèi)容</param>
  /// <param name="currentPage">當(dāng)前頁碼</param>
  /// <param name="pageUrl">當(dāng)前頁面地址</param>
  protected void ArticlePage(string content, int currentPage, string pageUrl)
  {
    pageUrl = !pageUrl.Contains("?") ? pageUrl + "?" : pageUrl.Replace("&cpage=" + currentPage, "");
    int pageCount = 0;//頁數(shù)
    content = content.Replace("<div style=\"page-break-after: always\"><span style=\"display: none\"> </span></div>", "[--page--]");//FCK在IE中生成的默認(rèn)分頁符,替換為自定義分頁符
    content = content.Replace("<div style=\"page-break-after: always\"><span style=\"display: none\"> </span></div>", "[--page--]");//FCK在FF中生成的默認(rèn)分頁符,替換為自定義分頁符
    string[] tempContent = System.Text.RegularExpressions.Regex.Split(content, "\\[--page--]"); //取得分頁符 "\\["為"["的轉(zhuǎn)義
    pageCount = tempContent.Length;
    string outputContent = "";//要輸出的內(nèi)容
    if (pageCount <= 1)
    {
      outputContent = content; //文章內(nèi)容
      this.pnlPage.Visible = false;
    }
    else
    {
      string pageStr = "";//分頁字符串
      pageStr += "共<span class='count'>" + pageCount + "</span>頁 ";
      if (currentPage != 1)
      {
        pageStr += " <a class='prev' href =" + pageUrl + "&cpage=" + (currentPage - 1) + ">上頁</a>";
      }
      for (int i = 1; i <= pageCount; i++)
      {
        if (i == currentPage)
          pageStr += (" <span class='active'>" + i + "</span>");
        else
          pageStr += (" <a class='num' href =" + pageUrl + "&cpage=" + i + ">" + i + "</a>");
      }
      if (currentPage != pageCount)
      {
        pageStr += " <a class='next' href =" + pageUrl + "&cpage=" + (currentPage + 1) + ">下頁</a>";
      }
      this.ltlPage.Text = pageStr;
      outputContent = tempContent[currentPage - 1].ToString();
    }
    this.ltlContent.Text = outputContent;
  }
}

更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net操作json技巧總結(jié)》、《asp.net字符串操作技巧匯總》、《asp.net操作XML技巧總結(jié)》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。

希望本文所述對大家asp.net程序設(shè)計有所幫助。

相關(guān)文章

最新評論