1.使用插件为 jquery.pagination.js ,如果没有这个js文件的话,我可以给发个。

首先引用 jquery.pagination.js (分页js),跟pagination.css(分页样式css)。

2.页面js代码为

<script type="text/javascript"> 

         var pageIndex = 0;     //页面索引初始值
var pageSize = 15; //每页显示条数初始化,修改显示条数,修改这里即可
$(function () {
InitTable(0); //Load事件,初始化表格数据,页面索引为0(第一页)
//分页,PageCount是总条目数,这是必选参数,其它参数都是可选
$("#Pagination").pagination(<%=pcount%>, {
callback: PageCallback, //PageCallback() 为翻页调用次函数。
prev_text: "« 上一页",
next_text: "下一页 »",
items_per_page:pageSize,
num_edge_entries: 2, //两侧首尾分页条目数
num_display_entries: 6, //连续分页主体部分分页条目数
current_page: pageIndex, //当前页索引
});
//翻页调用
function PageCallback(index, jq) {
InitTable(index);
}
//请求数据
function InitTable(pageIndex) {
$.ajax({
type: "POST",
dataType: "text",
url: 'http://www.cnblogs.com/tool/Reserver/ManageBuyBatchManage.ashx', //提交到一般处理程序请求数据
data: "pageIndex=" + (pageIndex) + "&pageSize=" + pageSize, //提交两个参数:pageIndex(页面索引),pageSize(显示条数)
success: function(data) {
$("#Result tr:gt(0)").remove(); //移除Id为Result的表格里的行,从第二行开始(这里根据页面布局不同页变)
$("#Result").append(data); //将返回的数据追加到表格
}
});
}
});
</script>

3.页面<body>里面的代码为

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="60" align="right">商品名:</td>
<td width="200" align="left"><input type="text" id="txtKeywords" class="keyword" /></td>
<td width="200" align="left"><input id="search" type="button" value=" 查 找 " class="submit" /></td>
<td >&nbsp;</td>
</tr>
</table>
<table id="Result" cellspacing="0" cellpadding="0">
<tr>
<th>商品编号</th>
<th>商品名称</th>
</tr>
</table>
<div id="Pagination" class="right flickr"></div>

4.页面后台代码为

protected int pcount = ;           //总条数
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BLL.TbGoods bll = new BLL.TbGoods();
pcount = bll.GetRecordCount("Status='" + (int)Enum.RecordStatus.Normal + "'"); //获取页面总条数,即要现实的数据总条数,还不明白的话,就是select count(*)from Table ,就是这里的个数。
}
}

5.一般处理程序ashx代码为

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data; namespace EShop.Web.Admin.tool.Reserver
{
/// <summary>
/// ListBuyBatchManage 的摘要说明
/// </summary>
public class ListBuyBatchManage : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
String str = string.Empty; if (context.Request["pageIndex"] != null && context.Request["pageIndex"].ToString().Length > )
{
int pageIndex; //具体的页面数
int.TryParse(context.Request["pageIndex"], out pageIndex);
if(context.Request["pageSize"]!=null&&context.Request["pageSize"].ToString().Length > )
{
//页面显示条数
int size = Convert.ToInt32(context.Request["pageSize"]);
string data= BindSource(size,pageIndex);
context.Response.Write(data);
context.Response.End();
}
} }
#region 无刷新分页
public string BindSource(int pagesize,int page)
{
BLL.TbGoods bll=new BLL.TbGoods();
DataSet ds = bll.GetListByPage("Status='" + (int)Enum.RecordStatus.Normal + "'", "", pagesize * page + , pagesize * (page + )); //获取数据源的ds会吧。
StringBuilder sb = new StringBuilder();
if (ds!=null)
{
foreach (DataRow row in ds.Tables[].Rows)
{
sb.Append("<tr><td>");
sb.Append(row["GoodsUid"]);
sb.Append("</td><td>");
sb.Append(row["GoodsName"]);
sb.Append("</td></tr>");
}
}
return sb.ToString();
}
#endregion public bool IsReusable
{
get
{
return false;
}
}
}
}

最新文章

  1. python-ldap实现登录案例
  2. 【C51】UART串口通信
  3. KVM虚拟机virsh常用参数
  4. Codeforces Round #360 (Div. 2) C D E
  5. 通过WebHandler给图片添加水印
  6. 《OD学算法》排序
  7. poi实现将数据输出到Excel表格当中
  8. 设置IE浏览器代理上网
  9. PERL高效代码摘录 - 数组
  10. Spring 入门 Ioc-Annotation
  11. SymmetricDS文档翻译--【Chapter 3. 具体配置(Configuration)[section C]】
  12. C++中数字与字符串之间的转换(使用CString.Format或者sprintf)
  13. HTML5游戏开发引擎Pixi.js完全入门手册(二)元素对象属性解析
  14. 4.事务提交过程,交易的基本概念,Oracle交易周期,保存点savepoint,数据库的隔离级别
  15. notepad++正则表达式替换字符串详解
  16. PHP将图片转base64编码以及base64图片转换为图片并保存代码
  17. 【译】第四篇 SQL Server安全权限
  18. 【转载】固态硬盘的S.M.A.R.T详解
  19. layer 中 的type和 content
  20. layer弹框插件使用

热门文章

  1. imx6 uart分析
  2. 第三百一十九节,Django框架,文件上传
  3. 用 #include &lt;filename.h&gt; 格式来引用标准库的头文件
  4. php -- 读取文本文件内容
  5. css -- outline轮廓
  6. Configurations of Vim/GVim of dsp
  7. QHeaderView的点击和双击事件
  8. Unity脚本中各函数成员的生命周期
  9. php跨form提交方法
  10. c++ _int64 转成string