?? 分頁(yè)顯示.txt
字號(hào):
ASP分頁(yè)代碼
<!-- #i nclude file="../conn.asp" --> //(Yoko:路徑按自己的設(shè)置好)
<%
dim i,intPage,page,pre,last,filepath
set rs = server.CreateObject("adodb.recordset")
sql="select * from user order by user_ID desc"
rs.PageSize = 20 //(Yoko:這里設(shè)定每頁(yè)顯示的記錄數(shù)
rs.CursorLocation = 3
rs.Open sql,conn,0,2,1 //(Yoko:'這里執(zhí)行你查詢SQL并獲得結(jié)果記錄集
pre = true
last = true
page = trim(Request.QueryString("page"))
if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs.PageCount then
intpage = rs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs.eof then
rs.AbsolutePage = intpage
end if
%>
<!--循環(huán)開(kāi)始-->
<%
for i=1 to rs.PageSize
if rs.EOF or rs.BOF then exit for
%>
..................
//(Yoko:要循環(huán)顯示的內(nèi)容 )..................
...................
<%
rs.movenext
next
%>
<!--循環(huán)體結(jié)束
分頁(yè)部分:-->
<table width="99%" border="1" cellpadding="2" cellspacing="2" borderColorLight=#808080 borderColorDark=#ffffff>
<tr>
<%if rs.pagecount > 0 then%>
<td width="13%" align="left">當(dāng)前頁(yè)<%=intpage%>/<%=rs.PageCount%></td>
<%else%>
<td width="41%" align="left">當(dāng)前頁(yè)0/0</td><%end if%>
<td width="46%" align="right"> <a href="本頁(yè).asp?page=1">首頁(yè)</a>|
<%if pre then%>
<a href="本頁(yè).asp?page=<%=intpage -1%>">上頁(yè)</a>| <%end if%>
<%if last then%>
<a href="本頁(yè).asp?page=<%=intpage +1%>">下頁(yè)</a> |<%end if%>
<a href="本頁(yè).asp?page=<%=rs.PageCount%>">尾頁(yè)</a>|轉(zhuǎn)到第
<select name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to rs.PageCount
if i = intpage then%>
<option value="本頁(yè).asp?page=<%=i%>" selected><%=i%></option>
<%else%>
<option value="本頁(yè).asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select>頁(yè)</font>
</td>
</tr>
</table>
下面是CSDN的:
<%
dim Conn,RS,sqlStr,PageSize,RowCount,TotalPages,PageNo,Position,PageBegin,PageEnd
set Conn= Server.CreateObject("ADODB.Connection")
set RS = Server.CreateObject("ADODB.RecordSet")
Conn.open "provider=sqloledb;data source=127.0.0.1;user id=sa;password=;initial catalog=zjydata"
sqlStr="select * from Items order by iID"
RS.open sqlStr,Conn,1,1
PageSize=10
If RS.RecordCount=0 then
%>
<TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=1 style='font-size:9pt'>
<TR bgcolor=#003366 height=20px>
<TD align=center><font color=#FFFFFF>商品代碼</font></TD>
<TD align=center><font color=#FFFFFF>商品名稱</font></TD>
<TD align=center><font color=#FFFFFF>型號(hào)規(guī)格</font></TD>
<TD align=center><font color=#FFFFFF>計(jì)量單位</font></TD>
<TD align=center><font color=#FFFFFF>參考進(jìn)價(jià)</font></TD>
<TD align=center><font color=#FFFFFF>參考售價(jià)</font></TD>
<TD align=center><font color=#FFFFFF>備注</font>
</TR>
<TR height=20px>
<TD align=center>沒(méi)有任何商品信息!</TD>
<TR>
</TABLE>
<%
else
RS.PageSize = Cint(PageSize)
TotalPages=RS.PageCount
PageNo=Request.QueryString("PageNo")
if PageNo="" or PageNo<1 Then
PageNo = 1
end if
RS.AbsolutePage = PageNo
Position=RS.PageSize*PageNo
PageBegin=Position-RS.PageSize+1
if Position <RS.RecordCount then
PageEnd=Position
else
PageEnd= RS.RecordCount
end if
%>
<TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=1 style='font-size:9pt'>
<TR>
<TD width=20%>
<%
Response.Write "頁(yè):"& PageNo &" / "& TotalPages &" | 記錄:"& PageBegin & " - " & PageEnd & " / " &RS.RecordCount
%>
</TD>
<TD align=right>
<%
if PageNo > 1 Then
response.write "<a href=list.asp?PageNo=1>首頁(yè)</a> <a href=list.asp?PageNo=" & (PageNo-1) & ">上頁(yè)</a> "
end if
if TotalPages > 1 and cint(PageNo) <> cint(TotalPages) then
response.write "<a href=list.asp?PageNo=" & (PageNo+1) & ">下頁(yè)</a> <a href=list.asp?PageNo=" & TotalPages & ">末頁(yè)</a> "
end if
%>
</TD>
</TR>
<TR bgcolor=#003366 height=20px>
<TD align=center width=20%><font color=#FFFFFF>商品代碼</font></TD>
<TD align=center width=30%><font color=#FFFFFF>商品名稱</font></TD>
<TD align=center width=8%><font color=#FFFFFF>型號(hào)規(guī)格</font></TD>
<TD align=center width=8%><font color=#FFFFFF>計(jì)量單位</font></TD>
<TD align=center width=8%><font color=#FFFFFF>參考進(jìn)價(jià)</font></TD>
<TD align=center width=8%><font color=#FFFFFF>參考售價(jià)</font></TD>
<TD align=center width=18%><font color=#FFFFFF>備注</font></TR>
<%
RowCount = RS.PageSize
dim color1,color2
color1="#dddddd"
color2="#eeeeee"
Do While Not RS.EOF and RowCount > 0
Response.Write "<TR height=20px bgcolor="
%>
<%
if RowCount mod 2=0 then:response.write color1 else:response.write color2
%>
<%
Response.Write ">"
%>
<TD><span><a href=manage.asp?id=<%=rs(0)%>><% =RS("vCode")%></a></span></td>
<TD><span><% =RS("vName")%></span></td>
<TD><span><% =RS("vSpec")%></span></TD>
<TD><span><% =RS("vUnit")%></span></td>
<TD><span><% =RS("fInPrice")%></span></td>
<TD><span><% =RS("fOutPrice")%></span></TD>
<TD><span><% =RS("vDescription")%></span></td>
</TR>
<%
RowCount = RowCount - 1
RS.MoveNext
Loop
Conn.Close
set RS = nothing
set Conn = nothing
%>
<TR bgcolor=#003366 height=20px>
<TD align=center width=20%><font color=#FFFFFF>商品代碼</font></TD>
<TD align=center width=30%><font color=#FFFFFF>商品名稱</font></TD>
<TD align=center width=8%><font color=#FFFFFF>型號(hào)規(guī)格</font></TD>
<TD align=center width=8%><font color=#FFFFFF>計(jì)量單位</font></TD>
<TD align=center width=8%><font color=#FFFFFF>參考進(jìn)價(jià)</font></TD>
<TD align=center width=8%><font color=#FFFFFF>參考售價(jià)</font></TD>
<TD align=center width=18%><font color=#FFFFFF>備注</font>
</TR>
<TR>
<TD>
<%
For i=1 to TotalPages
if CInt(PageNo) = CInt(i) then
response.write "["&i&"]"
else
response.write " <a href=list.asp?PageNo="&i&">"&i&"</a> "
end if
Next
%>
</TD>
</TR>
</TABLE>
<%
End if
%>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -