var objDiv; var _FunName = "/"; var _CurrentPageSize = 0; var _MaxPageSize = 0; var _PageSize = 5; var _IsUpDown = false; function InitPage(funName, currentPageSize, maxPageSize, pageSize, isUpDown) { _FunName = funName; _CurrentPageSize = currentPageSize; _MaxPageSize = maxPageSize; _PageSize = pageSize; _IsUpDown = isUpDown; } function ShowPage(objDiv) { var strResult = ""; var size = Math.floor(_PageSize / 2); var maxSize = _CurrentPageSize + size > _MaxPageSize ? _MaxPageSize : _CurrentPageSize + size; var minSize = _CurrentPageSize - size < 1 ? 1 : _CurrentPageSize - size; if (maxSize == _MaxPageSize) minSize = maxSize - _PageSize + 1; if (minSize == 1) maxSize = minSize + _PageSize - 1; var str = ""; for (var i = 0; i < _MaxPageSize; i++) { var curPage = i + 1; if (curPage == 1 || (curPage >= minSize && curPage <= maxSize) || curPage == _MaxPageSize) { var strPage = ""; if (curPage == minSize && (_CurrentPageSize > _PageSize || minSize > 2)) strPage += "... "; if (_CurrentPageSize == curPage) { strPage += " <a href="#" mce_href="#" style="font-size:14px;color:red" mce_style="font-size:14px;color:red">" + curPage + "</a>"; } else { strPage += " <a href="/" mce_href="/""#/" style="font-size:14px" mce_style="font-size:14px" onclick=/"" + _FunName + "(" + curPage + ");/">" + curPage + "</a>"; } if (curPage == maxSize && _MaxPageSize - _CurrentPageSize - 1 > size) { strPage += "... "; } strResult += strPage; } } strResult += ""; if (_IsUpDown) { if (_CurrentPageSize == 1) strResult = "<a href="#" mce_href="#" >上一页</a>" + strResult; else strResult = " <a href="/" mce_href="/""#/" onclick=/"" + _FunName + "(" + (_CurrentPageSize - 1) + ");/">上一页</a>" + strResult; if (_CurrentPageSize == _MaxPageSize) { strResult = strResult + " <a>下一页</a></ul>"; } else { strResult = strResult + " <a href="/" mce_href="/""#/" onclick=/"" + _FunName + "(" + (_CurrentPageSize + 1) + ");/">下一页</a>"; } } document.getElementById(objDiv).innerHTML = strResult; } HTML<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApp.Pager.WebForm1" %> <!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> <mce:script src="../JS/jquery-1.4.4.js" mce_src="JS/jquery-1.4.4.js"></mce:script> <mce:script src="../JS/PageViewJS.js" mce_src="JS/PageViewJS.js" type="text/javascript"></mce:script> <mce:script language="javascript" type="text/javascript"><!-- function GetCurPage(curPage) { //取当前页信息 document.forms[0].action = "WebForm1.aspx?Page=" + curPage; document.forms[0].submit(); } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div style="width: 1002px; margin: 0 auto;"> <div id="hdgz"><img src="images/sdzt_07.jpg" mce_src="images/sdzt_07.jpg" border="0" usemap="#Map" /></div> <div id="liebiao"> <div class="a_01" id="Container"> <ul class="lb"> <asp:DataList ID="ddlBlessingList" runat="server" Width="100%"> <ItemTemplate> <li class="bg01"> <table width="700" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="100" height="90" rowspan="2"> <img src="images/sdzt_02/img.jpg" mce_src="images/sdzt_02/img.jpg" class="lb_img" /> </td> <td width="600" align="left" valign="middle" class="font_07"> <%#Eval("User_Name")%> 对 【 <%#Eval("To_UserName")%>】说: </td> </tr> <tr> <td align="left" valign="top" class="font_07" style="word-break: break-all; width: 600px; overflow: auto;"> <%#Eval("To_Context")%> </td> </tr> </table> </li> </ItemTemplate> </asp:DataList> </ul> </div> <div class="fy"> <div id="divPage"> </div> </div> </div> <div id="back_zhufu"> </div> </div> </div> <asp:Literal ID="ltScript" runat="server"></asp:Literal> </form> </body> </html> JS 代码 后台代码 public partial class WebForm1 : System.Web.UI.Page { private int _MaxPageSize = 30; protected void Page_Load(object sender, EventArgs e) { int page = 1; if (Request.QueryString["Page"] != null && Request.QueryString["Page"].ToString() != "") { page = Convert.ToInt32(Request.QueryString["Page"]); } int _PageSize = 5; BindChristData(page, _PageSize); ltScript.Text = "<mce:script language=/"javascript/" type=/"text/javascript/"><!-- InitPage(/"GetCurPage/", " + page + ", " + _MaxPageSize + ", 8, true); ShowPage(/"divPage/"); // --></mce:script>"; } private void BindChristData(int pageIndex, int pageSize) { //int intStartIndex = (pageIndex - 1) * pageSize + 1; //int intEndIndex = pageIndex * pageSize; //DataSet tChrisTable = TChristmaxWishBLL.GetTChristmaxWish(intStartIndex, intEndIndex); //if (tChrisTable != null && tChrisTable.Tables[0].Rows.Count > 0) //{ // ddlBlessingList.DataSource = tChrisTable; // ddlBlessingList.DataBind(); // _MaxPageSize = Convert.ToInt32(tChrisTable.Tables[1].Rows[0][0].ToString()) % pageSize == 0 ? Convert.ToInt32(tChrisTable.Tables[1].Rows[0][0].ToString()) / pageSize : Convert.ToInt32(tChrisTable.Tables[1].Rows[0][0].ToString()) / pageSize + 1; } }