① asp分頁代碼
<%
'如果頁數大春凳告於1,則分頁顯示
self="visit_apply_list.asp"
if page_tot > 1 then
if currentpage > 1 then
response.write"<a href='"&self&"?search=enter&keyselect="&request("keyselect")&"&keyword=粗前"&request("keyword")&"&page=1'>首頁</a>-"
response.write"<a href='"&self&"?search=enter&keyselect="&request("keyselect")&"&keyword="&request("keyword")&"&page="¤tpage-1&"'>前頁</a>"
else
response.write"首扒明頁-</a>"
response.write"前頁</a>"
end if
if currentpage < page_tot then
response.write"-<a href='"&self&"?search=enter&keyselect="&request("keyselect")&"&keyword="&request("keyword")&"&page="& currentpage + 1&"'>後頁</a>"
response.write"-<a href='"&self&"?search=enter&keyselect="&request("keyselect")&"&keyword="&request("keyword")&"page="& page_tot&"'>尾頁</a>"
else
response.write"-後頁</a>"
response.write"-尾頁</a>"
end if
response.write" 頁次:"& currentpage &"/"& page_tot &" 20個記錄/頁 共"& r_t &"個記錄"
response.write" 轉到 <input name='page' type='text' size='2' value='"¤tpage&"'>"
response.write" <input type='submit' name='search' value='GO'>"
end if
%>
② 求最簡單的asp數據顯示和分頁代碼
這是一個簡短的分頁顯示的例子:
<%language="vbscript"
set conn=server.createobject("adodb.connection")
conn.oen "driver={sql server};server=huang;uid=sa;pwd=;database=test"
<%pgsize=5
page=request.querystring("page")
sql="select * from test where id1=1"
rs.open sql,conn,1
rs.pagesize=pgsize
pgnm=rs.pagecount
if page=""or clng(page)<1 then page=1
if clng(page)>pgnm then page=pgnm
if pgnm>0 then rs.absolutepage=page
count=0
do while not rs.eof and count<pgsize
%><%rs("id1")%><br>
<%=d%><br>
<%count=count+1
rs.movenext
loop
rs.close
set rs=nothing
%>
<a href=dis.asp?page=1>第一頁</A>
<A HREF=DIS.ASP?PAGE=<%=PGNM%>>最後一頁</A>
<A HREF=DIS.ASP?PAGE=<%=PAGE+1%>>下一頁</A>
<A HREF=DIS.ASP?PAGE=<%=PAGE-1%>>上一頁</A>
③ asp分頁程序代碼解釋100分送上!
<%
exec="select * from test" //設置查詢 TEST 表裡面的所有項目
set rs=server.createobject("adodb.recordset") //設置記錄集
rs.open exec,conn,1,1 //設置為只讀方式執行查詢
rs.PageSize=3 //設置分頁大小
pagecount=rs.PageCount //讀取總的頁數
page=int(request.QueryString ("page")) //取得用戶點擊傳過來的頁面號
if page<=0 then page=1 //如果傳過來的參數小於等於0 則是第一頁
if request.QueryString("page")="" then page=1 //如果傳過來的參數為空 則是第一頁
rs.AbsolutePage=page //指定游磨當前所在頁
%>
ASP記錄集方法,不一定非神早斗要設置為 rs. 這個可以隨意設置的,只要不是保留的變數
rs.movenext 將記錄指針從當前的位置向下移一行
rs.moveprevious 將記錄指針從當前的位置向上移一行
rs.movefirst 將記錄指針移到數據表第一行
rs.movelast 將記錄指針移到數據表最後一行
rs.absoluteposition=N 將記錄指針移到數據表第N行
rs.absolutepage=N 將記錄指針移到第N頁的第一行
rs.pagesize=N 設置每頁為N條記錄
rs.pagecount 根據 pagesize 的設置返回總頁數
rs.recordcount 返回記錄總數
rs.bof 返回記錄指針是否超出數據表首端,true表示是,false為否
rs.eof 返回記錄指針是否超出數據表末端,true表示是,false為否
rs.delete 刪除當前記錄,但記錄指針睜判不會向下移動
rs.addnew 添加記錄到數據表末端
rs.update 更新數據表記錄
④ asp代碼分頁
Function rsToPageHtml(rsPage,PageSize,rsUrl)
If rsPage.EOF Then
rsToPageHtml = "Nothing yet! Please check back later."
Exit Function
End If
Dim rsCount,PageCount,Page,sScriptName,strTemp
Dim tmpPage, intPage, allPage
rsCount = rsPage.RecordCount
rsPage.PageSize = PageSize
PageCount = rsPage.PageCount
Page = Request("Page")
if Page="" then
Page = 1
else
Page = Clng(Page)
end if
if Page < 1 then Page = 1
If Page > Pagecount Then Page = Pagecount
rsPage.AbsolutePage = Page
'sScriptName = Request.ServerVariables("SCRIPT_NAME")
if InstrRev(rsUrl,".asp?") > 0 then
rsUrl = rsUrl & "&Page="
else
rsUrl = rsUrl & "?Page="
end if
strTemp = ""
tmpPage = 10
intPage = Int((Page-1) / tmpPage)
allPage = Int(Pagecount / tmpPage)
If Page<>1 and intPage<>0 Then strTemp = strTemp &"<a href="褲旁""& rsUrl &"1"" title=首頁><font face=webdings>9</font></a> "
If intPage>0 Then strTemp = strTemp &"<a href="""& rsUrl & ((intPage-1)*tmpPage+1) &""" title=前十頁><font face=webdings>7</font></a> "
if page>1 then strTemp = strTemp &"<a href="""& rsUrl & page-1 &""" title=""上一頁""><font face=""webdings"">3</font></a> "
If intPage<allPage Then
For n=(intPage*tmpPage+1) To (intPage+1)*tmpPage
If n=Page Then
strTemp = strTemp &" <font color=red><b>"& n &"</b></font> "
Else
strTemp = strTemp &" <a href="""& rsUrl & n &"""><b>"& n &"</b></a> "
End If
Next
Else
For n=(intPage*tmpPage+1) To Pagecount
If n=Page Then
strTemp = strTemp &" <font color=red><b>"& n &"</b></font> "
Else
strTemp = strTemp &" <a href="""& rsUrl & n &"""><b>"& n &"</b></a> "
End If
Next
End If
if page<PageCount then strTemp = strTemp &"<a href="""& rsUrl & page+1 &""" title=""下一頁""><font face=""webdings"">4</font></a> "
If intPage<allPage Then strTemp = strTemp &"<a href="""& rsUrl & ((intPage+1)*tmpPage+1) &""" title=後十頁><font face=webdings> </臘高font></a> "
If Page<>Pagecount and intPage<>allPage Then strTemp = strTemp &"<a href="""& rsUrl & Pagecount &""" title=末頁><font face=webdings>:</font></a> "
strTemp = strTemp &" "& PageCount &輪純尺" pages "&" "&rsCount&" pics"
rsToPageHtml = strTemp
End Function
function ifspace(Name)
if Name<>"" then
ifspace=Name
else
ifspace="-"
end if
end function
⑤ asp分頁代碼
<%
function page(a,RCount,PCount,P,unl)'--------------分頁函數
if a=1 then
if p=1 then
show= "<input type=""submit"" name=""p1"" value=""首頁"" disabled >"
else
show= "<input type=""submit"" name=""p1"" value=""首頁"" onClick=""location.href='"&unl&"1';"" >"
end if
if p>1 then
show=show+" <input type=""submit"" name=""p2"" value=""上一頁"" onClick=""location.href='"&unl&p-1&"';"">"
else
show=show+" <input type=""submit"" name=""p2"" value=""上一頁"" disabled >"
end if
if p<PCount then
show=show+" <input type=""submit"" name=""p3"" value=""下一頁"" onClick=""location.href='"&unl&p+1&"';"">"逗升
else
show=show+" <input type=""submit"" name=""p3"" value=""下一頁"" disabled >"
end if
if p>=PCount then
show=show+" <input type=""submit"" name=""p4"" value=""末頁"" disabled>"
else
show=show+" <input type=""submit"" name=""p4"" value=""末頁"" onClick=""location.href='"&unl&PCount&"';"">"
end if
show=show+" 當前頁"&P&"/"&PCount&" 記錄總數"&RCount
end if
if a=2 then
show="<span class=""text"">"
show=show+"共有"&rcount&"個記錄"
if p=1 then
show=show+" | 首頁 "
else
show=show+" | <a href='"&unl&"1' class='text'>首頁</a> "
end if
if p>1 then
show=show+"| <a href='"&unl&p-1&"' class='text'>上一頁</a> "
else
show=show+"| 上一頁 "
end if
if p<pcount then
show=show+"| <a href='"&unl&p+1&"' class='text'>下一頁</a> "
else
show=show+"| 下一頁 "
end if
if p>=pcount then
show=show+"| 尾頁 "
else
show=show+"| <a href='"&unl&pcount&"' class='text'>尾頁</a> "
end if
show=show+"| 頁次:"&p&"/"&pcount&"頁 | 共"&pcount&"頁"
show=show+"</span>"
end if
if a=3 then
show="<span class=""text"">"
BlockPage=Int((P-1)/10)*10+1
IF BlockPage = 1 Then
show=show+ "<<"
else
show=show+ "<a href="&unl&BlockPage-1&" class=""text""><<</a>"
end if
i=1
Do Until i > 10 OR BlockPage > PCount
IF BlockPage=int(P) Then
show=show+ "<font color=red> "&BlockPage&帶明"</font>"
else
show=show+ "<a href="&unl&BlockPage&" class=""text""> "&BlockPage&"</a>"
end if
BlockPage=BlockPage+1
i = i + 1
Loop
if pcount>10 then
show=show+ "...<a href="&unl&pcount&" class=""text"">"&pcount&"</a>"
end if
if BlockPage>pcount then
show=show+ "蠢指告>> "
else
show=show+ "<a href="&unl&BlockPage&" class=""text"">>> </a>"
end if
show=show+"</span>"
end if
response.write show
end function
%>
⑥ 做一個簡單的ASP分頁程序
本程序主要用到Connection、RecordSet這兩個對象,程序中的資料庫為Access庫,採用OLEDB方式連接庫。
這個東西是作為菜鳥的我弄的一個東西.
你可以對這個東西不屑一顧.但是請記住: 菜鳥源喊衡也有這個權利把自己的心得體會附註文字貢獻出來.....當然,技術方面滲吵真的是好菜的..一些ASP中的比較正統的中規中矩的方法.我覺得這個東西可能對初學者有些幫助.......見笑了..
一個簡單的分頁教程:
<%
Setconn=Server.CreateObject("ADODB.Connection")
strcon="provider=microsoft.jet.oledb.4.0;datasource="&_
server.mappath("mdb.mdb")
conn.Openstrcon
Setrs=Server.CreateObject("ADODB.Recordset")
sql="select*fromtableorderbyiddesc"
rs.Opensql,conn,1
page=1'設置變數PAGE=1
rs.PageSize=5'每頁顯示記錄數
ifNotIsEmpty(Request("Page"))then'如果PAGE已經初始化...
Page=CInt(Request("Page"))'接收PAGE並化為數字型賦給PAGE變數
ifPage>rs.PageCountthen'如果接收的頁數大於總頁數
rs.AbsolutePage=rs.PageCount'設置當前顯示頁等於最後頁
elseifPage<=0then'如果page小於等於0
Page=1'設置PAGE等於第一頁
else
rs.AbsolutePage=Page'如果大於零,顯示當前頁等於接收的頁數
endif
Endif
Page=rs.AbsolutePage
%>
<%
Fori=1tors.PageSize
ifrs.EOFthen
ExitFor
endif'利用fornext循環雹做依次讀出記錄
%>