标签:
ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Pager2.ascx.cs" Inherits="com.eshop.www.Web.controls.Pager2" %> <div class="paginator-wrap" style="margin-right:10px;"> <div class="paginator"> <ul class="ul-wrap"> <li id="first" class="btn btn-m"> <a style="cursor:pointer;"> 首页 </a> </li> <li id="pre" class="btn btn-m"> <a style="cursor:pointer;"> 上一页 </a> </li> <li class="btn btn-m"> <a id="next" style="cursor:pointer;"> 下一页 </a> </li> <li class="btn btn-m"> <a id="end" style="cursor:pointer;"> 尾页 </a> </li> <li>页次:<em id="cp">1</em>/<em id="ye">0</em>页 共<em id="mc">0</em>条记录</li> <%--<li class="goto">到第</span><input type="text"><span class="words">页</span></li>--%> <%--<li class="submit"> <input type="submit" value="确定"></li>--%> </ul> </div> </div>
var PagerLib = {}; PagerLib.Pager = function (recordCount, opts) { opts = jQuery.extend({ pageSizeId: "PageSize", pageIndexId: "PageIndex", prev_text: "Prev", next_text: "Next", prev_show_always: true, next_show_always: true, callback: function () { return false; } }, opts || {}); var pageSize = 0; var pageIndex = 0; var pageCount = 0; function Init() { pageSize = parseInt($("#" + opts.pageSizeId).val()); pageIndex = parseInt($("#" + opts.pageIndexId).val()); if (recordCount % pageSize == 0) { pageCount = recordCount / pageSize; } else { pageCount = Math.ceil(recordCount / pageSize); } $("#ye").text(pageCount); $("#cp").text(pageIndex); $("#mc").text(recordCount); $("#first").click(function () { FirstPage(); }) $("#pre").click(function () { PrevPage(); }) $("#next").click(function () { NextPage(); }) $("#end").click(function () { EndPage(); }) } function NextPage() { if (pageIndex != pageCount) { pageIndex++; $("#" + opts.pageIndexId).val(pageIndex); $("#cp").text(pageIndex); //调用数据绑定方法 opts.callback(); } } function PrevPage() { if (pageIndex > 1) { pageIndex--; $("#" + opts.pageIndexId).val(pageIndex); $("#cp").text(pageIndex); //调用数据绑定方法 opts.callback(); } } function FirstPage() { if (pageIndex > 1) { pageIndex = 1; $("#" + opts.pageIndexId).val(pageIndex); $("#cp").text(pageIndex); //调用数据绑定方法 opts.callback(); } } function EndPage() { if (pageIndex != pageCount) { pageIndex = pageCount; $("#" + opts.pageIndexId).val(pageIndex); $("#cp").text(pageIndex); //调用数据绑定方法 opts.callback(); } } return { start: function () { Init(); } }; };
<script> $(function () { PagerLib.Pager(parseInt($("#RecordCount").val()), { pageSizeId: "PageSize", pageIndexId: "PageIndex", callback: BindData }).start(); }) function BindData() { $("#Button1").click(); } </script> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" style="display:none;" Text="Button" onclick="Button1_Click" /> <asp:HiddenField ID="RecordCount" runat="server" /> <asp:HiddenField ID="PageSize" runat="server" Value="5" /> <asp:HiddenField ID="PageIndex" runat="server" Value="1" />
标签:
原文地址:http://blog.csdn.net/hutao1101175783/article/details/45558273