一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - ASP.NET教程 - Asp.net+jquery+.ashx文件實(shí)現(xiàn)分頁思路

Asp.net+jquery+.ashx文件實(shí)現(xiàn)分頁思路

2019-10-30 16:10asp.net教程網(wǎng) ASP.NET教程

分頁思路: .ashx程序中,編寫好取得不同頁碼的程序。在頁面布局好的前提下,留下數(shù)據(jù)區(qū)域 div。然后在頁面請求 .ashx程序生成下一頁的html代碼。覆蓋div.innerHTMl

今天看到一個(gè).java哥們寫過的在頁面直接請求數(shù)據(jù)列表的程序代碼。它是實(shí)現(xiàn)選中客戶聯(lián)系人后,無刷新的彈出div羅列其它聯(lián)系人列表的功能。忽然想到既然可以請求聯(lián)系人列表,而且無刷新。那么取復(fù)雜的數(shù)據(jù)列表呢,后來想到了數(shù)據(jù)分頁。我現(xiàn)在用了自己寫的一個(gè)分頁控件。但是效率有時(shí)候感覺不是很高,它是以 用戶控件+存儲(chǔ)過程+分頁處理類 來實(shí)現(xiàn)分頁的。但是無可避免的就碰到了刷新的問題即使分頁很快,但是只要這“刷”的一下總是感覺很不爽。而且還要頁面編譯一遍,還要在服務(wù)端處理ViewState。以及其它的性能損失。既然 .ashx 可以 省略頁面編譯的過程。再把分頁處理類 挪到客戶端,那應(yīng)該是會(huì)性能提升不少,還沒有刷新,一定很爽,想到就做。 

我定的思路是: .ashx程序中,編寫好取得不同頁碼的程序。在頁面布局好的前提下,留下數(shù)據(jù)區(qū)域 div。然后在頁面請求 .ashx程序生成下一頁的html代碼。覆蓋div.innerHTMl 。 
首先是頁面,因?yàn)槭且獙?shí)踐思路,所以頁面真是很簡單。引用了jquery.js 

復(fù)制代碼代碼如下:


<div id="lab"> 
<input id="Button1" type="button" value="初始化數(shù)據(jù)" 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文件、實(shí)現(xiàn)客戶端的分頁控制。已經(jīng)在顯示頁面儲(chǔ)存了當(dāng)前頁碼信息 一個(gè)<input type='hidden'>。 
引用js文件后,就可以用了,哈哈,很順利。 

復(fù)制代碼代碼如下:


// 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="當(dāng)前第 "+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="當(dāng)前第 "+nextIndex+" 頁"; 
document.getElementById('currPageIndex').value=nextIndex; 
}); 


將它引用到顯示頁面 

復(fù)制代碼代碼如下:


<script type="text/javascript" src="http://www.cnblogs.com/Media/Script/jquery.js"></script> 
<script src="JScript.js" type="text/javascript"></script> 


搞定! 
剩下的就是服務(wù)端了,這個(gè)就簡單了,咱就是c#代碼出身,直接呼啦呼啦..... 
1、第一頁初始化的數(shù)據(jù)。.... 

復(fù)制代碼代碼如下:


<%@ 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'>稅號(hào)</th><th style='width:150px'>企業(yè)名稱</th><th style='width:200px'>企業(yè)地址</th><th style='width:150px'>銀行</th><th style='width:150px'>銀行賬號(hào)</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、點(diǎn)擊下一頁用到的 .ashx文件。 

復(fù)制代碼代碼如下:


<%@ 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'>稅號(hào)</th><th style='width:150px'>企業(yè)名稱</th><th style='width:200px'>企業(yè)地址</th><th style='width:150px'>銀行</th><th style='width:150px'>銀行賬號(hào)</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、點(diǎn)擊前一頁用到的.ashx文件。有思路了這個(gè)就更簡單了,直接就是copy了。 

復(fù)制代碼代碼如下:


<%@ 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'>稅號(hào)</th><th style='width:150px'>企業(yè)名稱</th><th style='width:200px'>企業(yè)地址</th><th style='width:150px'>銀行</th><th style='width:150px'>銀行賬號(hào)</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; 



完成!直接測試..效果果然很不錯(cuò),要知道我們的數(shù)據(jù)庫的數(shù)據(jù)量大概在10萬級(jí)別以上。..基本上感覺不到什么延時(shí)。還無刷新真是爽 啊,我要是用分頁的存儲(chǔ)過程,應(yīng)該還是會(huì)有所提升的。 
效果如圖、、順便畫了一幅抽象畫。哈哈...順便也欣賞一下吧。 
Asp.net+jquery+.ashx文件實(shí)現(xiàn)分頁思路
最后還是有點(diǎn)疑惑,.net的ajax 的用法是不是也是這樣呢?..以前用ajax就是用一些服務(wù)端控件,沒有真正實(shí)踐過客戶端的用法。但是我一直覺得ajax應(yīng)該和現(xiàn)在我實(shí)現(xiàn)的方式大同小異。以后再學(xué)習(xí)吧..對ajax精通的哥們們可以指教一下,客戶端的ajax的 經(jīng)典、實(shí)用的知識(shí)。先謝謝了。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩毛片免费线上观看 | 国产一级持黄大片99久久 | 色综久久天天综合绕视看 | 欧美一级在线全免费 | 9191久久 | 亚洲国产精品二区久久 | 喜爱夜蒲2三级做爰 | 免费特黄视频 | 色臀网站| 四虎影院免费在线播放 | 菠萝视频在线完整版 | 黑人干亚洲人 | 成人国产在线播放 | 国产精品香蕉 | vod国产成人精品视频 | xxx88视频在线观看 | 亚洲春黄在线观看 | 亚洲色图15p | 成人人免费夜夜视频观看 | 无限在线观看免费入口 | 范冰冰特黄xx大片 | 久久伊人中文字幕有码 | 亚洲一二三区视频 | 无码毛片内射白浆视频 | 福利片免费一区二区三区 | 亚洲系列第一页 | 清清草在线视频 | 交换朋友夫妇3中文字幕 | 国产日韩欧美色视频色在线观看 | 精品国产无限资源免费观看 | 欧美亚洲第一页 | 99久久精品无码一区二区毛片 | 国产三级精品91三级在专区 | 免费一看一级毛片人 | 欧美日韩在线一区 | 色综合久久夜色精品国产 | 美女牲交毛片一级视频 | 亚洲欧美精品久久 | 韩国三级在线 | 欧美高清乌克兰精品另类 | 久久亚洲电影www电影网 |