六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

ASP項目中的公共翻頁模塊

[摘要]在大型的ASP項目中,很多的頁面都涉及到翻頁功能。如果每個頁面都寫一個翻頁的程序的話,這樣的工作即降低了工作效率,也不利于工程的模塊化,不能使代碼重用。因此,把翻頁這樣的功能模塊化是很有必要的。 設計方法: 1、調用該模塊時,只需要傳遞記錄集和每頁顯示的記錄的條數; 2、可以點擊鏈接進行翻頁,也...
 在大型的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%>



主站蜘蛛池模板: 日韩毛片视频 | 日韩系列第一页 | 青草欧美 | 日本国产免费一区不卡在线 | 青草青草视频 | 欧洲性生活视频 | 日本亚洲视频 | 日本一区二区三 | 在线a视频 | 青春草a∨在线观看免费app | 小明精品国产一区二区三区 | 午夜免费片 | 欧美资源在线观看 | 亚洲视频二区 | 日韩 欧美 亚洲国产 | 天天躁狠狠躁狠狠躁夜夜躁 | 亚洲视频播放 | 午夜网站在线观看 | 亚洲黄色第一页 | 青草视频入口 在线观看 | 天天干夜夜做 | 中文字幕在线导航 | 欧美一卡二卡三卡四卡乱码 | 天堂tv| 四虎国产精品永免费 | 情不自禁完整版在线观看免费 | 欧美整片第一页 | 奇米久久 | 日本视频免费看 | 在线免费公开视频 | 人人看人人添人人谢 | 在线青草 | 四虎影院免费观看视频 | 日韩欧美极品 | 日本天堂在线视频 | 色综合久久天天影视网 | 亚洲国产成人在人网站天堂 | 日日摸夜夜欧美一区二区 | 中文字幕在线看视频一区二区三区 | 中文国产成人久久精品小说 | 亚洲图片综合区另类图片 |