页面无刷新分页
来源:互联网 发布:荷兰GPA算法 编辑:程序博客网 时间:2024/04/25 06:59
分页:页面无刷新源代码(由下面三部分组成)
一、前台代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#txtpagesize').val('5');
var pageindex = 0;
//获取总页数
function GetCount() {
ajax.WebService1.GetCount1(parseInt($('#txtpagesize').val()),onSuccess, onFailed);
totalpage = parseInt(result);
}
function onFailed() {
alert('调用失败');
}
function GetData() {
ajax.WebService1.DataBindArticlelist(parseInt($('#txtpagesize').val()),pageindex, onSuccess1, onFailed1);
}
function onSuccess1(result) {
var table = '<table border=1>';
table += '<tr><td>标题</td><td>类别</td><td>点击量</td><td>作者</td><td>出版日期</td></tr>'
for (var i = 0; i < result.length; i++) {
table += '<tr>';
//字段名称必须和后台类中属性名称一致
table += '<td>' + result[i]["Title"] + '</td>' + '<td>' + result[i]["Classname"] + '</td>' + '<td>' + result[i]["Clickcount"] + '</td>' + '<td>' + result[i]["Publisher"] + '</td>' + '<td>' + result[i]["Published"] + '</td>';
table += '</tr>';
}
table += '</table>';
$('#mydiv').html(table);
}
function onFailed1() {
alert('调用失败');
}
$('#btnfirst').click(function () {
pageindex = 1;
$('#txtpageindex').val(pageindex);
GetData();
})
$('#btnpre').click(function () {
if (pageindex > 1) {
pageindex--;
$('#txtpageindex').val(pageindex);
}
GetData();
})
$('#btnnext').click(function () {
if (pageindex < totalpage) {
pageindex++;
$('#txtpageindex').val(pageindex);
}
GetData();
})
//单击最后一页按钮时触发的事件
$('#btnlast').click(function () {
pageindex = totalpage;
$('#txtpageindex').val(pageindex);
GetData();
})
//单击Go按钮时触发的事件
$('#btngo').click(function () {
pageindex = $('#txtpageindex').val();
GetData();
})
$('#btnok').click(function () {
//根据当前设定获取总页数
GetCount();
//重新加载第一页
$('#btnfirst').click();
})
//页面加载时获取总页数并显示第一页
GetCount();
$('#btnfirst').click();
})
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebService1.asmx" />
</Services>
</asp:ScriptManager>
<div id="mydiv"></div>
<div>
<input id="btnfirst" type="button" value="第一页" /><input id="btnpre" type="button"
value="上一页" /><input id="btnnext" type="button" value="下一页" /><input id="btnlast"
type="button" value="最后一页" /><input id="txtpageindex" type="text" /><input id="btngo"
type="button" value="GO" /><br />
设定每页显示条数<input id="txtpagesize" type="text" /><input id="btnok" type="button"
value="确定" /><br />
</form>
</body>
</html>
二、web服务代码
namespace ajax
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
string strcon = ConfigurationManager.ConnectionStrings["strcon"].ConnectionString;
private int pagesize = 5;
//返回list
[WebMethod]
public List<articleinfo> DataBindArticlelist(int pagesizeuser, int pageindex)
{
SqlConnection conn = new SqlConnection(strcon);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "PROFENYE";
//表明调用的是存储过程
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@PAGESIZE", pagesizeuser);
cmd.Parameters.AddWithValue("@PAGEINDEX", pageindex);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
List<articleinfo> list = new List<articleinfo>();
for (int i = 0; i < dt.Rows.Count; i++)
{
string title = Convert.ToString(dt.Rows[i]["TITLE"]);
string classname = Convert.ToString(dt.Rows[i]["CLASSNAME"]);
string clickcount = Convert.ToString(dt.Rows[i]["CLICKCOUNT"]);
string publisher = Convert.ToString(dt.Rows[i]["PUBLISHER"]);
string published = Convert.ToString(dt.Rows[i]["PUBLISHED"]);
articleinfo article = new articleinfo()
{
Title = title,
Classname = classname,
Clickcount = clickcount,
Publisher = publisher,
Published = published
};
list.Add(article);
}
cmd.Dispose();
conn.Close();
conn.Dispose();
return list;
}
//根据用户设定每页显示的记录数量
//获取总的页数
[WebMethod]
public string GetCount1(int pagesizeuser)
{
int totalpagesize = 0;
SqlConnection conn = new SqlConnection(strcon);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select count(*) from ArticleInfo";
conn.Open();
object obj = cmd.ExecuteScalar();
if (obj != null)
{
int totalrecord = Convert.ToInt32(obj);
if (totalrecord % pagesize != 0)
{
totalpagesize = totalrecord / pagesizeuser + 1;
}
else
{
totalpagesize = totalrecord / pagesizeuser;
}
}
cmd.Dispose();
conn.Dispose();
return totalpagesize.ToString();
}
}
}
三、创建类
namespace ajax
{
public class articleinfo
{
private string title;
public string Title
{
get { return title; }
set { title = value; }
}
private string classname;
public string Classname
{
get { return classname; }
set { classname = value; }
}
private string clickcount;
public string Clickcount
{
get { return clickcount; }
set { clickcount = value; }
}
private string publisher;
public string Publisher
{
get { return publisher; }
set { publisher = value; }
}
private string published;
public string Published
{
get { return published; }
set { published = value; }
}
}
}
一、前台代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#txtpagesize').val('5');
var pageindex = 0;
//获取总页数
function GetCount() {
ajax.WebService1.GetCount1(parseInt($('#txtpagesize').val()),onSuccess, onFailed);
}
totalpage = parseInt(result);
}
function onFailed() {
alert('调用失败');
}
function GetData() {
ajax.WebService1.DataBindArticlelist(parseInt($('#txtpagesize').val()),pageindex, onSuccess1, onFailed1);
}
function onSuccess1(result) {
var table = '<table border=1>';
table += '<tr><td>标题</td><td>类别</td><td>点击量</td><td>作者</td><td>出版日期</td></tr>'
for (var i = 0; i < result.length; i++) {
table += '<tr>';
//字段名称必须和后台类中属性名称一致
table += '<td>' + result[i]["Title"] + '</td>' + '<td>' + result[i]["Classname"] + '</td>' + '<td>' + result[i]["Clickcount"] + '</td>' + '<td>' + result[i]["Publisher"] + '</td>' + '<td>' + result[i]["Published"] + '</td>';
table += '</tr>';
}
table += '</table>';
$('#mydiv').html(table);
}
function onFailed1() {
alert('调用失败');
}
$('#btnfirst').click(function () {
pageindex = 1;
$('#txtpageindex').val(pageindex);
GetData();
})
$('#btnpre').click(function () {
if (pageindex > 1) {
pageindex--;
$('#txtpageindex').val(pageindex);
}
GetData();
})
$('#btnnext').click(function () {
if (pageindex < totalpage) {
pageindex++;
$('#txtpageindex').val(pageindex);
}
GetData();
})
//单击最后一页按钮时触发的事件
$('#btnlast').click(function () {
pageindex = totalpage;
$('#txtpageindex').val(pageindex);
GetData();
})
//单击Go按钮时触发的事件
$('#btngo').click(function () {
pageindex = $('#txtpageindex').val();
GetData();
})
$('#btnok').click(function () {
//根据当前设定获取总页数
GetCount();
//重新加载第一页
$('#btnfirst').click();
})
//页面加载时获取总页数并显示第一页
GetCount();
$('#btnfirst').click();
})
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebService1.asmx" />
</Services>
</asp:ScriptManager>
<div id="mydiv"></div>
<div>
<input id="btnfirst" type="button" value="第一页" /><input id="btnpre" type="button"
value="上一页" /><input id="btnnext" type="button" value="下一页" /><input id="btnlast"
type="button" value="最后一页" /><input id="txtpageindex" type="text" /><input id="btngo"
type="button" value="GO" /><br />
设定每页显示条数<input id="txtpagesize" type="text" /><input id="btnok" type="button"
value="确定" /><br />
</form>
</body>
</html>
二、web服务代码
namespace ajax
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
string strcon = ConfigurationManager.ConnectionStrings["strcon"].ConnectionString;
private int pagesize = 5;
//返回list
[WebMethod]
public List<articleinfo> DataBindArticlelist(int pagesizeuser, int pageindex)
{
SqlConnection conn = new SqlConnection(strcon);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "PROFENYE";
//表明调用的是存储过程
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@PAGESIZE", pagesizeuser);
cmd.Parameters.AddWithValue("@PAGEINDEX", pageindex);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
List<articleinfo> list = new List<articleinfo>();
for (int i = 0; i < dt.Rows.Count; i++)
{
string title = Convert.ToString(dt.Rows[i]["TITLE"]);
string classname = Convert.ToString(dt.Rows[i]["CLASSNAME"]);
string clickcount = Convert.ToString(dt.Rows[i]["CLICKCOUNT"]);
string publisher = Convert.ToString(dt.Rows[i]["PUBLISHER"]);
string published = Convert.ToString(dt.Rows[i]["PUBLISHED"]);
articleinfo article = new articleinfo()
{
Title = title,
Classname = classname,
Clickcount = clickcount,
Publisher = publisher,
Published = published
};
list.Add(article);
}
cmd.Dispose();
conn.Close();
conn.Dispose();
return list;
}
//根据用户设定每页显示的记录数量
//获取总的页数
[WebMethod]
public string GetCount1(int pagesizeuser)
{
int totalpagesize = 0;
SqlConnection conn = new SqlConnection(strcon);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select count(*) from ArticleInfo";
conn.Open();
object obj = cmd.ExecuteScalar();
if (obj != null)
{
int totalrecord = Convert.ToInt32(obj);
if (totalrecord % pagesize != 0)
{
totalpagesize = totalrecord / pagesizeuser + 1;
}
else
{
totalpagesize = totalrecord / pagesizeuser;
}
}
cmd.Dispose();
conn.Dispose();
return totalpagesize.ToString();
}
}
}
三、创建类
namespace ajax
{
public class articleinfo
{
private string title;
public string Title
{
get { return title; }
set { title = value; }
}
private string classname;
public string Classname
{
get { return classname; }
set { classname = value; }
}
private string clickcount;
public string Clickcount
{
get { return clickcount; }
set { clickcount = value; }
}
private string publisher;
public string Publisher
{
get { return publisher; }
set { publisher = value; }
}
private string published;
public string Published
{
get { return published; }
set { published = value; }
}
}
}
- 页面无刷新分页
- 关于无刷新页面的分页
- jquery+PHP实现无刷新页面分页
- JQUERY+PHP实现无刷新页面分页 jq页面不刷新完成分页例子
- jquery如何实现在jsp页面中的无刷新分页
- 上架下架,修改js无页面刷新分页搜索
- ajax静态页面无刷新添加留言,无刷新分页,翻页综合应用
- ajax静态页面无刷新添加留言,无刷新分页,翻页综合应用
- PHP + AJAX 实现无刷新分页 不刷新页面实现分页 PHP AJAX
- PHP + AJAX 实现无刷新分页 不刷新页面实现分页 PHP AJAX
- 无刷新分页控件
- Repeater 无刷新分页
- 无刷新分页
- Repeater无刷新分页
- 分页无刷新
- php 无刷新分页
- ajax 无刷新分页
- 无刷新分页
- DB2多分区数据库的常用管理
- 高斯(核)函数简介
- Code::Blocks 10.05的安装及使用
- AIX操作系统配置IP地址方法
- Oracle中游标的使用
- 页面无刷新分页
- web xml
- 第一个项目
- 读取内存
- 发布分发分离演示
- 类(空类/虚基类等)占内存的空间
- 常用的几个提高iOS开发效率的开源类库及工具
- 并查集(不相交集合)
- Tomcat6.0与Apache的整合(http-proxy方式)