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

服務(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í)。先謝謝了。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 午夜免费无码福利视频麻豆 | 特级淫片大乳女子高清视频 | 日本公乱妇视频 | 国产色在线观看 | 国产爽视频 | 九九国产在线观看 | 成人国产午夜在线视频 | 亚洲国产精品久久精品成人网站 | 免费看日产一区二区三区 | 国产香蕉97碰碰在线视频 | 玩两个少妇女邻居 | 99av导航 | 欧美最猛性xxxxx短视频 | 免费国产一级观看完整版 | 成人精品一区二区三区中文字幕 | 超逼网| 女人张开腿 让男人桶个爽 免费观看 | 特黄视频 | 久久精品嫩草影院免费看 | 欧美日韩一区二区三区久久 | 五月一区二区久久综合天堂 | 女人又色又爽又黄 | 午夜亚洲WWW湿好爽 午夜想想爱午夜剧场 | a毛片免费全部在线播放毛 a级在线看 | 4444www免费看 | 日韩国产欧美一区二区三区 | 精品日韩一区二区三区 | 色亚洲色图 | 变态np虐高h| 毛片a区| 久久这里有精品 | 亚洲麻豆精品果冻传媒 | 欧美最猛性xxxxx动态图 | 成人aqq| 日韩高清在线高清免费 | 日韩欧美一区二区三区中文精品 | 国产永久免费视频m3u8 | 日韩一级片在线免费观看 | 国产绳艺在线播放 | 维修工的调教 | 免费看欧美一级特黄a大片一 |