web 分页方法

        /// <summary>
        /// 输出翻页控件HTML
        /// </summary>
        /// <param name="recordsum">总数据条数</param>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页数</param>
        /// <param name="pageFormat">分页字符串</param>
        /// <param name="ifJavascript">是否为js分页</param>
        /// <returns>翻页控件HTML</returns>
        public static string GetPagerStr(int recordsum, int pageSize, int pageIndex, string pageFormat, bool ifJavascript = false)
        {
            string pagestr = "";
            //如果总条目小于pageSize,那么什么都不输出
            if (recordsum <= pageSize)
            {
                return "";
            }
            if (ifJavascript)//是js分页,就使用onclick
            {
                pageFormat = "javascript:;\" οnclick=\"" + pageFormat;
            }
            int pagesum = recordsum % pageSize == 0 ? recordsum / pageSize : recordsum / pageSize + 1;//共多少页
            if (pageIndex > pagesum)
                pageIndex = 1;
            string formstr = "<div class=\"pager\">";
            if (pageIndex > 1)
            {
                formstr += string.Format("<a href=\"" + pageFormat + "\">上一页</a>", (pageIndex - 1));
            }
            else
            {
                formstr += string.Format("<span class='pagerpre'>上一页</span>");
            }
            int count = pageIndex + 3 > pagesum ? pagesum : pageIndex + 3;
            if (count - 7 > 0)
            {
                formstr += string.Format("<a href=\"" + pageFormat + "\">...</a>", count - 7);
            }
            for (int i = count - 7 > 0 ? count - 7 : 0; i < count; i++)
            {
                if (i + 1 != pageIndex)
                {
                    formstr += string.Format("<a href=\"" + pageFormat + "\">" + (i + 1) + "</a>", (i + 1));
                }
                else
                {
                    formstr += "<span>" + (i + 1) + "</span>";
                }
            }
            if (count < pagesum)
            {
                formstr += string.Format("<a href=\"" + pageFormat + "\">...</a>", count + 1);
            }
            if (pageIndex < pagesum) formstr += string.Format("<a href=\"" + pageFormat + "\">下一页</a>", (pageIndex + 1));
            else
            {
                formstr += string.Format("<span class='pagernext'>下一页</span>", (pageIndex + 1));
            }
            //if (recordsum > 0) formstr += "<li>共{4}页</li>";
            formstr += "</div>";
            pagestr = string.Format(formstr, pageIndex - 1, pageIndex + 1, pageIndex, recordsum, pagesum, recordsum);
            return pagestr;
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值