明霞山资源网 Design By www.htccd.com
今天看到一个.java哥们写过的在页面直接请求数据列表的程序代码。它是实现选中客户联系人后,无刷新的弹出div罗列其它联系人列表的功能。忽然想到既然可以请求联系人列表,而且无刷新。那么取复杂的数据列表呢,后来想到了数据分页。我现在用了自己写的一个分页控件。但是效率有时候感觉不是很高,它是以 用户控件+存储过程+分页处理类 来实现分页的。但是无可避免的就碰到了刷新的问题即使分页很快,但是只要这“刷”的一下总是感觉很不爽。而且还要页面编译一遍,还要在服务端处理ViewState。以及其它的性能损失。既然 .ashx 可以 省略页面编译的过程。再把分页处理类 挪到客户端,那应该是会性能提升不少,还没有刷新,一定很爽,想到就做。
我定的思路是: .ashx程序中,编写好取得不同页码的程序。在页面布局好的前提下,留下数据区域 div。然后在页面请求 .ashx程序生成下一页的html代码。覆盖div.innerHTMl 。
首先是页面,因为是要实践思路,所以页面真是很简单。引用了jquery.js
复制代码 代码如下:
<div id="lab">
<input id="Button1" type="button" value="初始化数据" onclick="Init();" />
<div id="Content" style="width: 100%">
</div>
<div id="PagePanel" style="margin-left:20px"><label id="pageInfo"></label><a href="#" onclick="InitUp()">Last</a> <a href="#" onclick="InitNext()">Next</a></div>
<input type="hidden" value="0" id="currPageIndex" />
</div>
然后编写.js文件、实现客户端的分页控制。已经在显示页面储存了当前页码信息 一个<input type='hidden'>。
引用js文件后,就可以用了,哈哈,很顺利。
复制代码 代码如下:
// JScript 文件
function Init()
{
$.get("Handler.ashx", function (tablestr) {
document.getElementById('Content').innerHTML=tablestr;
document.getElementById('currPageIndex').value='1';
});
}
function InitNext()
{
var currIndex=document.getElementById('currPageIndex').value;
var nextIndex=Number(currIndex)+1;
$.get("NextHandler.ashx",{index:currIndex},function (tablestr) {
document.getElementById('Content').innerHTML=tablestr;
document.getElementById('pageInfo').innerText="当前第 "+nextIndex+" 页";
document.getElementById('currPageIndex').value=nextIndex;
});
}
function InitUp()
{
var currIndex=document.getElementById('currPageIndex').value;
var nextIndex=Number(currIndex)-1;
$.get("PreviousHandler.ashx",{index:currIndex},function (tablestr) {
document.getElementById('Content').innerHTML=tablestr;
document.getElementById('pageInfo').innerText="当前第 "+nextIndex+" 页";
document.getElementById('currPageIndex').value=nextIndex;
});
}
将它引用到显示页面
复制代码 代码如下:
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.js"><script src="JScript.js">
搞定!
剩下的就是服务端了,这个就简单了,咱就是c#代码出身,直接呼啦呼啦.....
1、第一页初始化的数据。....
复制代码 代码如下:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Data;
using System.Text;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
DataSet ds = HebHX.DBUtility.DbHelperSQL.Query("select top 20 cust_code,cust_name,cust_addr,bank_name,bank_account from customer_info");
StringBuilder tb = new StringBuilder("<table class='dateGrid'><tr><th style='width:130px'>税号</th><th style='width:150px'>企业名称</th><th style='width:200px'>企业地址</th><th style='width:150px'>银行</th><th style='width:150px'>银行账号</th><tr>");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
tb.Append("<tr>");
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
tb.Append("<td class='Item'>");
tb.Append(ds.Tables[0].Rows[i][j].ToString());
tb.Append("</td>");
}
tb.Append("</tr>");
}
tb.Append("</table>");
context.Response.Write(tb.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
2、点击下一页用到的 .ashx文件。
复制代码 代码如下:
<%@ WebHandler Language="C#" Class="NextHandler" %>
using System;
using System.Web;
using System.Data;
using System.Text;
public class NextHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
int pageRows = 20;
int pageIndex = Convert.ToInt32(context.Request.Params["index"]) + 1;
DataSet ds = HebHX.DBUtility.DbHelperSQL.Query("select top " + pageRows.ToString() + " cust_code,cust_name,cust_addr,bank_name,bank_account from customer_info where cust_id> (select max(t.cust_id) from (select top " + (pageRows * pageIndex).ToString() + " cust_id from customer_info order by cust_id) t) order by cust_id");
StringBuilder tb = new StringBuilder("<table class='dateGrid'><tr><th style='width:130px'>税号</th><th style='width:150px'>企业名称</th><th style='width:200px'>企业地址</th><th style='width:150px'>银行</th><th style='width:150px'>银行账号</th><tr>");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
tb.Append("<tr>");
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
tb.Append("<td class='Item'>");
tb.Append(ds.Tables[0].Rows[i][j].ToString());
tb.Append("</td>");
}
tb.Append("</tr>");
}
tb.Append("</table>");
context.Response.Write(tb.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
3、点击前一页用到的.ashx文件。有思路了这个就更简单了,直接就是copy了。
复制代码 代码如下:
<%@ WebHandler Language="C#" Class="UpHandler" %>
using System;
using System.Web;
using System.Data;
using System.Text;
public class UpHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
int pageRows = 20;
int pageIndex = Convert.ToInt32(context.Request.Params["index"]) - 1;
DataSet ds = HebHX.DBUtility.DbHelperSQL.Query("select top " + pageRows.ToString() + " cust_code,cust_name,cust_addr,bank_name,bank_account from customer_info where cust_id> (select max(t.cust_id) from (select top " + (pageRows * pageIndex).ToString() + " cust_id from customer_info order by cust_id) t) order by cust_id");
StringBuilder tb = new StringBuilder("<table class='dateGrid'><tr><th style='width:130px'>税号</th><th style='width:150px'>企业名称</th><th style='width:200px'>企业地址</th><th style='width:150px'>银行</th><th style='width:150px'>银行账号</th><tr>");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
tb.Append("<tr>");
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
tb.Append("<td class='Item'>");
tb.Append(ds.Tables[0].Rows[i][j].ToString());
tb.Append("</td>");
}
tb.Append("</tr>");
}
tb.Append("</table>");
context.Response.Write(tb.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
完成!直接测试..效果果然很不错,要知道我们的数据库的数据量大概在10万级别以上。..基本上感觉不到什么延时。还无刷新真是爽 啊,我要是用分页的存储过程,应该还是会有所提升的。
效果如图、、顺便画了一幅抽象画。哈哈...顺便也欣赏一下吧。

最后还是有点疑惑,.net的ajax 的用法是不是也是这样呢?..以前用ajax就是用一些服务端控件,没有真正实践过客户端的用法。但是我一直觉得ajax应该和现在我实现的方式大同小异。以后再学习吧..对ajax精通的哥们们可以指教一下,客户端的ajax的 经典、实用的知识。先谢谢了。
我定的思路是: .ashx程序中,编写好取得不同页码的程序。在页面布局好的前提下,留下数据区域 div。然后在页面请求 .ashx程序生成下一页的html代码。覆盖div.innerHTMl 。
首先是页面,因为是要实践思路,所以页面真是很简单。引用了jquery.js
复制代码 代码如下:
<div id="lab">
<input id="Button1" type="button" value="初始化数据" onclick="Init();" />
<div id="Content" style="width: 100%">
</div>
<div id="PagePanel" style="margin-left:20px"><label id="pageInfo"></label><a href="#" onclick="InitUp()">Last</a> <a href="#" onclick="InitNext()">Next</a></div>
<input type="hidden" value="0" id="currPageIndex" />
</div>
然后编写.js文件、实现客户端的分页控制。已经在显示页面储存了当前页码信息 一个<input type='hidden'>。
引用js文件后,就可以用了,哈哈,很顺利。
复制代码 代码如下:
// JScript 文件
function Init()
{
$.get("Handler.ashx", function (tablestr) {
document.getElementById('Content').innerHTML=tablestr;
document.getElementById('currPageIndex').value='1';
});
}
function InitNext()
{
var currIndex=document.getElementById('currPageIndex').value;
var nextIndex=Number(currIndex)+1;
$.get("NextHandler.ashx",{index:currIndex},function (tablestr) {
document.getElementById('Content').innerHTML=tablestr;
document.getElementById('pageInfo').innerText="当前第 "+nextIndex+" 页";
document.getElementById('currPageIndex').value=nextIndex;
});
}
function InitUp()
{
var currIndex=document.getElementById('currPageIndex').value;
var nextIndex=Number(currIndex)-1;
$.get("PreviousHandler.ashx",{index:currIndex},function (tablestr) {
document.getElementById('Content').innerHTML=tablestr;
document.getElementById('pageInfo').innerText="当前第 "+nextIndex+" 页";
document.getElementById('currPageIndex').value=nextIndex;
});
}
将它引用到显示页面
复制代码 代码如下:
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.js"><script src="JScript.js">
搞定!
剩下的就是服务端了,这个就简单了,咱就是c#代码出身,直接呼啦呼啦.....
1、第一页初始化的数据。....
复制代码 代码如下:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Data;
using System.Text;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
DataSet ds = HebHX.DBUtility.DbHelperSQL.Query("select top 20 cust_code,cust_name,cust_addr,bank_name,bank_account from customer_info");
StringBuilder tb = new StringBuilder("<table class='dateGrid'><tr><th style='width:130px'>税号</th><th style='width:150px'>企业名称</th><th style='width:200px'>企业地址</th><th style='width:150px'>银行</th><th style='width:150px'>银行账号</th><tr>");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
tb.Append("<tr>");
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
tb.Append("<td class='Item'>");
tb.Append(ds.Tables[0].Rows[i][j].ToString());
tb.Append("</td>");
}
tb.Append("</tr>");
}
tb.Append("</table>");
context.Response.Write(tb.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
2、点击下一页用到的 .ashx文件。
复制代码 代码如下:
<%@ WebHandler Language="C#" Class="NextHandler" %>
using System;
using System.Web;
using System.Data;
using System.Text;
public class NextHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
int pageRows = 20;
int pageIndex = Convert.ToInt32(context.Request.Params["index"]) + 1;
DataSet ds = HebHX.DBUtility.DbHelperSQL.Query("select top " + pageRows.ToString() + " cust_code,cust_name,cust_addr,bank_name,bank_account from customer_info where cust_id> (select max(t.cust_id) from (select top " + (pageRows * pageIndex).ToString() + " cust_id from customer_info order by cust_id) t) order by cust_id");
StringBuilder tb = new StringBuilder("<table class='dateGrid'><tr><th style='width:130px'>税号</th><th style='width:150px'>企业名称</th><th style='width:200px'>企业地址</th><th style='width:150px'>银行</th><th style='width:150px'>银行账号</th><tr>");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
tb.Append("<tr>");
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
tb.Append("<td class='Item'>");
tb.Append(ds.Tables[0].Rows[i][j].ToString());
tb.Append("</td>");
}
tb.Append("</tr>");
}
tb.Append("</table>");
context.Response.Write(tb.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
3、点击前一页用到的.ashx文件。有思路了这个就更简单了,直接就是copy了。
复制代码 代码如下:
<%@ WebHandler Language="C#" Class="UpHandler" %>
using System;
using System.Web;
using System.Data;
using System.Text;
public class UpHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
int pageRows = 20;
int pageIndex = Convert.ToInt32(context.Request.Params["index"]) - 1;
DataSet ds = HebHX.DBUtility.DbHelperSQL.Query("select top " + pageRows.ToString() + " cust_code,cust_name,cust_addr,bank_name,bank_account from customer_info where cust_id> (select max(t.cust_id) from (select top " + (pageRows * pageIndex).ToString() + " cust_id from customer_info order by cust_id) t) order by cust_id");
StringBuilder tb = new StringBuilder("<table class='dateGrid'><tr><th style='width:130px'>税号</th><th style='width:150px'>企业名称</th><th style='width:200px'>企业地址</th><th style='width:150px'>银行</th><th style='width:150px'>银行账号</th><tr>");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
tb.Append("<tr>");
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
tb.Append("<td class='Item'>");
tb.Append(ds.Tables[0].Rows[i][j].ToString());
tb.Append("</td>");
}
tb.Append("</tr>");
}
tb.Append("</table>");
context.Response.Write(tb.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
完成!直接测试..效果果然很不错,要知道我们的数据库的数据量大概在10万级别以上。..基本上感觉不到什么延时。还无刷新真是爽 啊,我要是用分页的存储过程,应该还是会有所提升的。
效果如图、、顺便画了一幅抽象画。哈哈...顺便也欣赏一下吧。

最后还是有点疑惑,.net的ajax 的用法是不是也是这样呢?..以前用ajax就是用一些服务端控件,没有真正实践过客户端的用法。但是我一直觉得ajax应该和现在我实现的方式大同小异。以后再学习吧..对ajax精通的哥们们可以指教一下,客户端的ajax的 经典、实用的知识。先谢谢了。
标签:
jquery,ashx,分页
明霞山资源网 Design By www.htccd.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
明霞山资源网 Design By www.htccd.com
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。