惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
D
Docker
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Recent Announcements
Recent Announcements
GbyAI
GbyAI
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
L
LangChain Blog
A
About on SuperTechFans
M
MIT News - Artificial intelligence
B
Blog

博客园 - 冰凌水心

导入文本格式数据到数据库中 截取字符串中数字和字母函数 GridView在RowCommand取得当前行和列的值 NHibernate学习笔记收藏 javascript小技巧 全/半角转换,间繁体转换 常用JS (转) UrlRewrite、地址映射技术 返回距离指定日期的天数 截断字符,如果文章字数超过指定字符个数,用省列号代替 数字转汉字函数(转自http://www.cnblogs.com/deadshot123/archive/2006/11/18/564521.html) IBM Rational AppScan:跨站点脚本攻击深入解析 常用正则表达式 链接 SQL2005的一点记录 将文字内容和图片插入到 Access 数据库 Repeater嵌套Repeater实现分类并绑定分页 只查询当前页 类实现.NET框架下的加密和解密(网上找来的,忘记是哪位大侠的杰作了) 改写别人的分页控件代码
改写别人的分页控件代码(有加密)
冰凌水心 · 2008-08-22 · via 博客园 - 冰凌水心

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.Text;
using PTFair.WebSites.Common;

public partial class Controls_Pager : System.Web.UI.UserControl
{
    private string _UrlFormat;
    private string _UrlPar;
    private int _PageSize;
    private int _RecordCount;
    private int _PageCount = 5;
    private int flag = 0;
    private int _SetPageIndex = 0;
    Security mySecurity;

    /// <summary>
    /// 连接页面
    /// </summary>
    public string UrlFormat
    {
        get
        {
            return _UrlFormat;
        }
        set
        {
            _UrlFormat = value;
        }
    }

    /// <summary>
    /// 链接参数
    /// </summary>
    public string UrlPar
    {
        get
        {
            return _UrlPar;
        }
        set
        {
            _UrlPar = value;
        }
    }

    /// <summary>
    /// 每页显示记录数

    /// </summary>
    public int PageSize
    {
        get
        {
            return _PageSize;
        }
        set
        {
            _PageSize = value;
        }
    }

    /// <summary>
    /// 当前页码
    /// </summary>
    public int PageIndex
    {
        get
        {
            string Pageindex;
            if (SetPageIndex == 1)
                Pageindex = "1";
            else
            {
                if (Request["list"] != null)
                {
                    mySecurity = new Security();
                    string pars = mySecurity.DecryptQueryString(Request["list"]);
                    string[] tmplist = pars.Split(',');
                    Pageindex = tmplist[0];// HttpContext.Current.Request.QueryString["list"];
                }
                else
                    Pageindex = "1";
            }
            if (Pageindex != null)
            {
                return int.Parse(Pageindex);
            }
            return 1;
        }
    }

    /// <summary>
    /// 初始话当前页为第一页

    /// </summary>
    public int SetPageIndex
    {
        get
        {
            return _SetPageIndex;
        }
        set
        {
            _SetPageIndex = value;
        }
    }

    /// <summary>
    /// 总记录数
    /// </summary>
    public int RecordCount
    {
        get
        {
            return _RecordCount;
        }
        set
        {
            _RecordCount = value;
        }
    }

    /// <summary>
    /// 两边显示个数
    /// </summary>
    public int PageCount
    {
        get
        {
            return _PageCount;
        }
        set
        {
            _PageCount = value;
        }
    }

    protected override void Render(HtmlTextWriter writer)
    {
        if (PageSize == 0)
            PageSize = int.Parse(ConfigurationSettings.AppSettings["PageSize"]);
        PageCount = System.Convert.ToInt32(Math.Ceiling((Decimal)RecordCount / PageSize));//获取页数
        if (RecordCount == 0)
            return;
        int SumPage = (RecordCount + PageSize - 1) / PageSize;//页数?

        flag = (PageIndex - 1) / 10;
        StringBuilder sb = new StringBuilder(string.Format("页次:{0}/{1}&nbsp;&nbsp;每页:{2}&nbsp;&nbsp;共计:{3}条&nbsp;&nbsp;", PageIndex, SumPage, PageSize, RecordCount));
        mySecurity = new Security();
        if (PageIndex > 1)
        {
            sb.Append("<a href=\"" + UrlFormat + mySecurity.EncryptQueryString(string.Format(UrlPar, 1)) + "\">首页</a> ");
            sb.Append(" <a href=\"" + UrlFormat + mySecurity.EncryptQueryString(string.Format(UrlPar, PageIndex - 1)) + "\">上一页</a> ");
        }
        if (this.PageIndex > 10)
        {
            sb.Append("<a href=\"" + UrlFormat + mySecurity.EncryptQueryString(string.Format(UrlPar, 10 * flag)) + "\"><<</a> ");
        }
        int start, end;
        start = 10 * flag + 1;
        if (10 * (flag + 1) > PageCount)
        {
            end = PageCount;
        }
        else
        {
            end = 10 * (flag + 1);
        }

        for (int i = start; i <= end; i++)
        {
            if (i == PageIndex)
            {
                sb.Append(" <strong>" + PageIndex.ToString() + "</strong> ");
            }
            else
            {
                sb.Append("<a href=\"" + UrlFormat + mySecurity.EncryptQueryString(string.Format(UrlPar, i)) + "\">" + i + "</a> ");
            }
            sb.Append("&nbsp;");
        }
        if (PageCount > 10 * (flag + 1))
        {
            sb.Append("<a href=\"" + UrlFormat + mySecurity.EncryptQueryString(string.Format(UrlPar, 10 * (flag + 1) + 1)) + "\">>></a> ");
        }
        if (PageIndex < SumPage)
        {
            sb.Append(" <a href=\"" + UrlFormat + mySecurity.EncryptQueryString(string.Format(UrlPar, PageIndex + 1)) + "\">下一页</a> ");
            sb.Append(" <a href=\"" + UrlFormat + mySecurity.EncryptQueryString(string.Format(UrlPar, SumPage)) + "\">尾页</a>");
        }
        writer.Write(sb.ToString());
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}