欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP項(xiàng)目中的公共翻頁模塊

 更新時(shí)間:2006年12月13日 00:00:00   作者:  
在大型的ASP項(xiàng)目中,很多的頁面都涉及到翻頁功能。如果每個(gè)頁面都寫一個(gè)翻頁的程序的話,這樣的工作即降低了工作效率,也不利于工程的模塊化,不能使代碼重用。因此,把翻頁這樣的功能模塊化是很有必要的。  
設(shè)計(jì)方法: 
1、調(diào)用該模塊時(shí),只需要傳遞記錄集和每頁顯示的記錄的條數(shù); 
2、可以點(diǎn)擊鏈接進(jìn)行翻頁,也可以直接輸入頁碼,回車后翻頁; 
3、不要考慮文件名,程序的每次翻頁都能在當(dāng)前頁面。 

想清楚了上面3個(gè)問題,我們的公共翻頁模塊就可以動(dòng)手了。 

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

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

'獲取當(dāng)前文件名,使得每次翻頁都在當(dāng)前頁面進(jìn)行; 
Dim fileName,postion 
fileName = Request.ServerVariables("script_name") 
postion = InstrRev(fileName,"/")+1 
'取得當(dāng)前的文件名稱,使翻頁的鏈接指向當(dāng)前文件; 
fileName = Mid(fileName,postion)  
%> 
<table border=0 width='100%'>  
<tr>  
<td align=left> 總頁數(shù):<font color=#ff3333><%=TotalPage%></font>頁 
當(dāng)前第<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>轉(zhuǎn)到第 
<%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=請輸入頁號(hào),然后回車> 
<%End If%>頁 
</td> 
</tr> 
</table> 
<%End Sub%> 

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

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

'----------------------------------------------------- 
調(diào)用范例: 
文件名: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 '每頁顯示的記錄條數(shù) 
Call TurnPage(Rs_News,RowCount)  
'公共翻頁模塊結(jié)束%>  

<table width=100%> 
<tr> 
<td>新聞編號(hào)</td> 
<td>新聞標(biāo)題</td> 
<td>發(fā)布日期</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 
%> 

而那個(gè)公共模塊缺<form>,改后: 
<% 
Sub TurnPage(ByRef Rs_tmp,PageSize) 'Rs_tmp 記錄集 ; PageSize 每頁顯示的記錄條數(shù); 
Dim TotalPage '總頁數(shù) 
Dim PageNo '當(dāng)前顯示的是第幾頁 
Dim RecordCount '總記錄條數(shù) 
Rs_tmp.PageSize = PageSize 
RecordCount = Rs_tmp.RecordCount 
TotalPage = INT(RecordCount / PageSize * -1)*-1 
PageNo = Request.QueryString ("PageNo") 
'直接輸入頁數(shù)跳轉(zhuǎn); 
If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo") 
'如果沒有選擇第幾頁,則默認(rèn)顯示第一頁; 
If PageNo = "" then PageNo = 1  
If RecordCount <> 0 then 
Rs_tmp.AbsolutePage = PageNo 
End If 
'獲取當(dāng)前文件名,使得每次翻頁都在當(dāng)前頁面進(jìn)行; 
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> 總頁數(shù):<font color=#ff3333><%=TotalPage%></font>頁  
當(dāng)前第<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=""> 轉(zhuǎn)到第 <% 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%>

相關(guān)文章

最新評論