当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net jquery无刷新分页插件(jquery.pagination.js)

asp.net jquery无刷新分页插件(jquery.pagination.js)

2017年12月12日  | 移动技术网IT编程  | 我要评论

星光大赏2017,轮胎钢圈,电视剧勇敢的心全集

采用jquery无刷新分页插件jquery.pagination.js 实现无刷新分页效果
友情提示:本示例handler中采用stringbuilder的append方法追加html,小数据量可以,但是大数据或是布局常变,建议返回json格式的数据,性能和灵活性更好!

1.插件参数列表

 
2.页面内容

复制代码 代码如下:

<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default"%>
<!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>porschev----无刷新翻页</title>
<script src="script/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="script/jquery.pagination.js" type="text/javascript"></script>
<script src="script/tablecloth.js" type="text/javascript"></script>
<link href="style/tablecloth.css" rel="stylesheet" type="text/css"/>
<link href="style/pagination.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
var pageindex =0; //页面索引初始值
var pagesize =10; //每页显示条数初始化,修改显示条数,修改这里即可
$(function() {
inittable(0); //load事件,初始化表格数据,页面索引为0(第一页)
//分页,pagecount是总条目数,这是必选参数,其它参数都是可选
$("#pagination").pagination(<%=pagecount %>, {
callback: pagecallback,
prev_text: '上一页', //上一页按钮里text
next_text: '下一页', //下一页按钮里text
items_per_page: pagesize, //显示条数
num_display_entries: 6, //连续分页主体部分分页条目数
current_page: pageindex, //当前页索引
num_edge_entries: 2//两侧首尾分页条目数
});
//翻页调用
function pagecallback(index, jq) {
inittable(index);
}
//请求数据
function inittable(pageindex) {
$.ajax({
type: "post",
datatype: "text",
url: 'handler/pagerhandler.ashx', //提交到一般处理程序请求数据
data: "pageindex="+ (pageindex +1) +"&pagesize="+ pagesize, //提交两个参数:pageindex(页面索引),pagesize(显示条数)
success: function(data) {
$("#result tr:gt(0)").remove(); //移除id为result的表格里的行,从第二行开始(这里根据页面布局不同页变)
$("#result").append(data); //将返回的数据追加到表格
}
});
}
});
</script>
</head>
<body>
<div align="center">
<h1>posrchev----无刷新分页</h1>
</div>
<div id="container">
<table id="result" cellspacing="0" cellpadding="0">
<tr>
<th>编号</th>
<th>名称</th>
</tr>
</table>
<div id="pagination"></div>
</div>
</body>
</html>

3.页面.cs文件内容
复制代码 代码如下:

using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
public partial class _default : system.web.ui.page
{
public string pagecount = string.empty; //总条目数
protected void page_load(object sender, eventargs e)
{
if (!ispostback)
{
pagecount = new pagertestbll.personmanager().getpersoncount().tostring();
}
}
}

4.handler中的内容
复制代码 代码如下:

<%@ webhandler language="c#" class="pagerhandler" %>
using system;
using system.web;
using system.collections.generic;
using system.text;
public class pagerhandler : ihttphandler {
public void processrequest (httpcontext context) {
context.response.contenttype = "text/plain";
string str = string.empty;
//具体的页面数
int pageindex;
int.tryparse(context.request["pageindex"], out pageindex);
//页面显示条数
int size = convert.toint32(context.request["pagesize"]);
if (pageindex == 0)
{
pageindex = 1;
}
int count;
list<pagertestmodels.person> list = new pagertestbll.personmanager().getallperson(size, pageindex, "", out count);
stringbuilder sb = new stringbuilder();
foreach (pagertestmodels.person p in list)
{
sb.append("<tr><td>");
sb.append(p.id.tostring());
sb.append("</td><td>");
sb.append(p.name);
sb.append("</td></tr>");
}
str = sb.tostring();
context.response.write(str);
}
public bool isreusable {
get {
return false;
}
}
}

5.实现效果图


如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网