国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

ASP項目中的公共翻頁模塊

2020-07-27 13:21:17
字體:
來源:轉載
供稿:網友
在大型的ASP項目中,很多的頁面都涉及到翻頁功能。如果每個頁面都寫一個翻頁的程序的話,這樣的工作即降低了工作效率,也不利于工程的模塊化,不能使代碼重用。因此,把翻頁這樣的功能模塊化是很有必要的。  
設計方法: 
1、調用該模塊時,只需要傳遞記錄集和每頁顯示的記錄的條數; 
2、可以點擊鏈接進行翻頁,也可以直接輸入頁碼,回車后翻頁; 
3、不要考慮文件名,程序的每次翻頁都能在當前頁面。 

想清楚了上面3個問題,我們的公共翻頁模塊就可以動手了。 

<% 
'+++++++++++++++++++++++++++++++++++++ 
'◆模塊名稱: 公共翻頁模塊 
'◆文 件 名: TurnPage.asp 
'◆傳入參數: Rs_tmp (記錄集), PageSize (每頁顯示的記錄條數) 
'◆輸 出: 記錄集翻頁顯示功能 
'+++++++++++++++++++++++++++++++++++++ 

Sub TurnPage(ByRef Rs_tmp,PageSize) 'Rs_tmp 記錄集 ; PageSize 每頁顯示的記錄條數; 
Dim TotalPage '總頁數 
Dim PageNo '當前顯示的是第幾頁 
Dim RecordCount '總記錄條數 
Rs_tmp.PageSize = PageSize 
RecordCount = Rs_tmp.RecordCount 
TotalPage = INT(RecordCount / PageSize * -1)*-1 
PageNo = Request.QueryString ("PageNo") 
'直接輸入頁數跳轉; 
If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo") 
'如果沒有選擇第幾頁,則默認顯示第一頁; 
If PageNo = "" then PageNo = 1  
If RecordCount <> 0 then 
Rs_tmp.AbsolutePage = PageNo 
End If 

'獲取當前文件名,使得每次翻頁都在當前頁面進行; 
Dim fileName,postion 
fileName = Request.ServerVariables("script_name") 
postion = InstrRev(fileName,"/")+1 
'取得當前的文件名稱,使翻頁的鏈接指向當前文件; 
fileName = Mid(fileName,postion)  
%> 
<table border=0 width='100%'>  
<tr>  
<td align=left> 總頁數:<font color=#ff3333><%=TotalPage%></font>頁 
當前第<font color=#ff3333><%=PageNo%></font>頁</td> 
<td align="right">  
<%If RecordCount = 0 or TotalPage = 1 Then  
Response.Write "首頁|前頁|后頁|末頁" 
Else%> 
<a href="<%=fileName%>?PageNo=1">首頁|</a> 
<%If PageNo - 1 = 0 Then 
Response.Write "前頁|" 
Else%> 
<a href="<%=fileName%>?PageNo=<%=PageNo-1%>">前頁|</a> 
<%End If 

If PageNo+1 > TotalPage Then 
Response.Write "后頁|" 
Else%> 
<a href="<%=fileName%>?PageNo=<%=PageNo+1%>">后頁|</a> 
<%End If%> 

<a href="<%=fileName%>?PageNo=<%=TotalPage%>">末頁</a> 
<%End If%></td> 
<td width=95>轉到第 
<%If TotalPage = 1 Then%> 
<input type=text name=PageNo size=3 readonly disabled style="background:#d3d3d3"> 
<%Else%> 
<input type=text name=PageNo size=3 value="" title=請輸入頁號,然后回車> 
<%End If%>頁 
</td> 
</tr> 
</table> 
<%End Sub%> 

當然,大家可以把翻頁的鏈接做成圖片按鈕,這樣的話也面就更加美觀了。 

調用方法: 
1、在程序開始或要使用翻頁的地方包含翻頁模塊文件; 
2、定義變量:RowCount,每頁顯示的記錄條數 
3、調用翻頁過程:Call TurnPage(記錄集,RowCount) 
4、在Do While 循環輸出記錄集的條件中加上" RowCount > 0 " 條件 
5、在循環結束 "Loop前" 加上: RowCount = RowCount - 1 

'----------------------------------------------------- 
調用范例: 
文件名:News.asp 

<% 
Dim Conn,Rs_News 
Set Conn = server.CreateObject("ADODB.CONNECTION") 
Conn.Open "cpm","cpm","cpm" 

Dim Sql 
Sql = "Select * from News" 
Set Rs_News = Server.CreateObject("ADODB.RECORDSET") 
Rs_News.Open Sql,Conn,1,3 '獲取的記錄集 

'公共翻頁模塊開始%> 
<!--#include file=../Public/TurnPage.asp--> 
<% 
Dim RowCount 
RowCount = 10 '每頁顯示的記錄條數 
Call TurnPage(Rs_News,RowCount)  
'公共翻頁模塊結束%>  

<table width=100%> 
<tr> 
<td>新聞編號</td> 
<td>新聞標題</td> 
<td>發布日期</td> 
<tr> 
<% 
If Not Rs_News.eof 
Do while Not Rs_News.eof and RowCount>0 
%> 
<tr> 
<td><%=Rs_News("ID")%></td> 
<td><%=Rs_News("Name")%></td> 
<td><%=Rs_News("Date")%></td> 
<tr> 
<% 
RowCount = RowCount - 1 
Rs_News.MoveNext 
Loop 
End If 
%> 



修正: 
<% 
If Not Rs_News.eof then 
Do while Not Rs_News.eof and RowCount>0 
%> 

而那個公共模塊缺<form>,改后: 
<% 
Sub TurnPage(ByRef Rs_tmp,PageSize) 'Rs_tmp 記錄集 ; PageSize 每頁顯示的記錄條數; 
Dim TotalPage '總頁數 
Dim PageNo '當前顯示的是第幾頁 
Dim RecordCount '總記錄條數 
Rs_tmp.PageSize = PageSize 
RecordCount = Rs_tmp.RecordCount 
TotalPage = INT(RecordCount / PageSize * -1)*-1 
PageNo = Request.QueryString ("PageNo") 
'直接輸入頁數跳轉; 
If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo") 
'如果沒有選擇第幾頁,則默認顯示第一頁; 
If PageNo = "" then PageNo = 1  
If RecordCount <> 0 then 
Rs_tmp.AbsolutePage = PageNo 
End If 
'獲取當前文件名,使得每次翻頁都在當前頁面進行; 
Dim fileName,postion 
fileName = Request.ServerVariables("script_name") 
postion = InstrRev(fileName,"/")+1 
fileName = Mid(fileName,postion)  
%> 
<table border=0 width='100%'>  
<tr>  
<td width="258" align=left> 總頁數:<font color=#ff3333><%=TotalPage%></font>頁  
當前第<font color=#ff3333><%=PageNo%></font>頁 總共<%=RecordCount%>條 </td> 
<td width="308" align="right"> <div align="center">  
<%If RecordCount = 0 or TotalPage = 1 Then  
Response.Write "首頁|前頁|后頁|末頁" 
Else%> 
<a href="<%=fileName%>?PageNo=1">首頁|</a>  
<%If PageNo - 1 = 0 Then 
Response.Write "前頁|" 
Else%> 
<a href="<%=fileName%>?PageNo=<%=PageNo-1%>">前頁|</a>  
<%End If 

If PageNo+1 > TotalPage Then 
Response.Write "后頁|" 
Else%> 
<a href="<%=fileName%>?PageNo=<%=PageNo+1%>">后頁|</a>  
<%End If%> 
<a href="<%=fileName%>?PageNo=<%=TotalPage%>">末頁</a>  
<%End If%> 
</div></td> 
<td width=189><form name="form1" method="post" action=""> 轉到第 <% If TotalPage = 1 Then%> 
<input type=text name=PageNo size=3 readonly disabled style="background:#d3d3d3"> 
<input type="submit" name="Submit" value="Go" disabled style="background:#d3d3d3"> 
<%Else%> 
<input type=text name=PageNo size=3 > 
<input type="submit" name="Submit" value="Go"> 
<%End If%> 
</form> 
頁  
</td> 
</tr> 
</table> 
<%End Sub%>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 延川县| 抚顺县| 格尔木市| 英吉沙县| 南靖县| 司法| 阜康市| 榆社县| 宁海县| 河北区| 玛多县| 兴义市| 呈贡县| 崇左市| 长沙市| 巴彦淖尔市| 内江市| 宣威市| 通化市| 稻城县| 盖州市| 白山市| 抚宁县| 肇东市| 南昌市| 瑞昌市| 河津市| 香格里拉县| 云林县| 禄劝| 贵定县| 宁陵县| 罗源县| 琼结县| 曲周县| 黑河市| 河曲县| 白河县| 琼结县| 达州市| 延安市|