zoukankan      html  css  js  c++  java
  • 长文章分页代码类

    提供一个重载,默认有一个分页符,分割采用正则表达式,样式名是page,或者自己改。

    需引入using System.Text.RegularExpressions;

        /// <summary>
    /// 长文章分页
    /// </summary>
    public class SplictPage
    {
    /// <summary>
    /// 长文章分页
    /// </summary>
    /// <param name="content">欲分割的内容</param>
    /// <param name="pageingFlag">分割标识符</param>
    /// <param name="sprarm">传递的参数,如:newsid=1</param>
    /// <returns></returns>
    public static string bind(string content,string pageingFlag, string sprarm)
    {
    string thisnr = "";
    string thispage = "";
    int currpagenum;

    string[] temp = Regex.Split(content, pageingFlag, RegexOptions.IgnoreCase);

    try
    {
    currpagenum = System.Convert.ToInt32(System.Web.HttpContext.Current.Request.QueryString["page"]);
    if (currpagenum <= 0)
    {
    currpagenum = 1;
    }

    if (currpagenum > temp.Length)
    {
    currpagenum = temp.Length;
    }
    }
    catch
    {
    return "error";
    }

    if (System.Web.HttpContext.Current.Request.QueryString["page"] == null)
    {
    thisnr = temp[0];
    }
    else
    {
    thisnr = temp[currpagenum - 1];
    }

    if (temp.Length > 1)
    {
    thispage = "<div class=\"page\"><a href=\"?" + sprarm + "&page=1\" style=\"auto;border:0;\">首页</a>";
    thispage += "<a href=\"?" + sprarm + "&page=" + (currpagenum - 1) + "\" style=\"auto;border:0;\">上一页</a>";
    for (int i = 0; i <= temp.Length - 1; i++)
    {
    if (i == currpagenum - 1)
    {
    thispage += "<font>" + (i + 1) + "</font>";
    }
    else
    {
    thispage += "<a href=?" + sprarm + "&page=" + (i + 1) + ">" + (i + 1) + "</a>";
    }
    }
    thispage += "<a href=\"?" + sprarm + "&page=" + (currpagenum + 1) + "\" style=\"auto;border:0;\">下一页</a>";
    thispage += "<a href=\"?" + sprarm + "&page=" + temp.Length + "\" style=\"auto;border:0;\">末页</a></div>";
    }
    return thisnr + thispage;
    }

    /// <summary>
    /// 长文章分页,默认分页标识:<div>\\$HengCmsPage\\$</div>
    /// </summary>
    /// <param name="content">欲分割的内容</param>
    /// <param name="sprarm">传递的参数,如:newsid=1</param>
    /// <returns></returns>
    public static string bind(string content, string sprarm)
    {
    return bind(content, "<div>\\$HengCmsPage\\$</div>", sprarm);
    }
    }
  • 相关阅读:
    Python批量爬取唯美类图片
    查找Windows启动程序
    在Windows10中进行蓝屏排查
    在Windows 10中应该记住的完整的多指触摸板手势
    通过命令行工具远程注销用户
    Windows 7,8.1和10中的隐藏退出资源管理器选项
    找出正在使用的全局热键
    windows10中创建环境变量
    mysql高级(锁机制)
    mysql高级(查询截取分析)
  • 原文地址:https://www.cnblogs.com/superfeeling/p/2346165.html
Copyright © 2011-2022 走看看