今天心情有点激动,想把"关于用dw asp实现分页技术的参考"分享给用dw asp做网页的朋友们.去掉只有"第一页,前一页,下一页,最后一页"的小痛苦
此效果最后的显示是:第n页[共*页] <<1 2 3 4 5 6 7 8 9 10 >>。
用dw asp做网页时,在绑定记录集后,代码页里马上出现以下代码:
<%
dim recordset1
dim recordset1_numrows
set recordset1 = server.createobject("adodb.recordset")
recordset1.activeconnection = mm_数据库名_string
recordset1.source = "select * from 表名"
recordset1.cursortype = 0
recordset1.cursorlocation = 2
recordset1.locktype = 1
recordset1.open()
recordset1_numrows = 0
%>
<%
dim i
dim rpp
dim pageno
i=1
rpp=50
pageno=cint(request("pageno"))
’上面即是新插入的,
dim recordset1
dim recordset1_numrows
set recordset1 = server.createobject("adodb.recordset")
recordset1.activeconnection = mm_数据库名_string
recordset1.source = "select * from 数据库名"
recordset1.cursortype = 1 ’将上面代码的0改为1.
recordset1.cursorlocation = 2
recordset1.locktype = 1
recordset1.open()
recordset1_numrows = 0 ’再在此行的下一行开始加入如下代码:
recordset1.pagesize=rpp
if pageno<=0 then pageno=1
if pageno>recordset1.pagecount then pageno=recordset1.pagecount
recordset1.absolutepage=pageno
sub showpageinfo(tpagecount,cpageno)
response.write "第"&cpageno&"页[共"&tpagecount&"页]"
end sub
sub showpagenavi(tpagecount,cpageno)
if cpageno<1 then cpageno=1
if tpagecount<1 then tpagecount=1
if cpageno>tpagecount then cpageno=tpagecount
dim navilength
navilength=10 ’navilength:显示的数字链接个数
dim i,startpage,endpage
startpage=(cpageno/navilength)*navilength 1
if (cpageno mod navilength)=0 then startpage=startpage-navilength
endpage=startpage navilength-1
if endpage>tpagecount then endpage=tpagecount
if startpage>1 then
response.write "<a class=""pagenavi"" href=""?pageno=" & (cpageno-navilength) & """><<</a> "
else
response.write "<font color=""#cccccc""><<</font> "
end if
for i=startpage to endpage
if i=cpageno then
response.write "<b>"&i&"</b>"
else
response.write "<a class=""pagenavi"" href=""?pageno=" & i & """>" & i & "</a>"
end if
if i<>tpagecount then response.write " "
next
if endpage<tpagecount then
response.write " <a class=""pagenavi"" href=""?pageno=" & (cpageno navilength) & """>>></a>"
else
response.write " <font color=""#cccccc"">>></font> "
end if
end sub
%>
上面代码中:rpp:指定每页显示的记录条数。即每页显示几条数据。
navilength:显示的数字链接个数,即10就为1 2 3 ...10的连接个数。 |||
若要显示所有连接的页(个)数,你可以设置为:navilength=tpagecount。
这时代码已经差不多了,但还要在显示的地方(如表格)中加点代码才行吧,(要不然怎么显示,呵~~~)如我们插入一个2行3列的表格。
1.将光标移在第一行第一列中,切换到代码中加入:<%=(pageno-1)*rpp i%>
这个代码是显示序号用的。
2.右边2个单元格(当然你自己可以根据需要分更多的列)就是为你要显示的记录了。请分别从绑定的记录集中选中你要显示的字段拖放在相应的单元格中,(也可以选中后再点右下角的“插入”按钮)。这里我们就先拖2个进来如“编号”和“公司名称”。分别到1行第2个单元格和1行第3个单元格中。
3.这个是个要害的,请将光标移到第一行任意单元格中,再来点选窗口底下的<tr>,这时你看看代码,<tr>....</tr>就被选中了。这时请在<tr>....</tr>的前面插入如下代码:
<%
if recordset1.eof or recordset1.bof then
else
for i=1 to rpp
%>再在<tr>....</tr>之后插入如下代码:
<%
recordset1.movenext
if recordset1.eof or recordset1.bof then exit for
next
end if
%>
<% showpageinfo recordset1.pagecount,pageno %>
的代码。右边的2个单元格将其合并,在代码中插入:<% showpagenavi recordset1.pagecount,pageno %>
的代码。
5.大功告成!这时感快预览一下吧。。。。
表格的全部代码如下:
<table width="710" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#333333">
<%
if recordset1.eof or recordset1.bof then
else
for i=1 to rpp
%>
<tr bgcolor="#ffffff">
<td width="30" align="center"><%=(pageno-1)*rpp i%></td>
<td><%=(recordset1.fields.item("编号").value)%></td>
<td><%=(recordset1.fields.item("公司名称").value)%></td>
</tr>
<%
recordset1.movenext
if recordset1.eof or recordset1.bof then exit for
next
end if
%>
<tr bgcolor="#ffffff">
<td colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr bgcolor="#006699" class="w12">
<td width="121" align="center"><% showpageinfo recordset1.pagecount,pageno %>
</td>
<td width="573" align="center">
<% showpagenavi recordset1.pagecount,pageno %>
</td>
</tr>
</table></td>
</tr>
</table>
<%
dim i
dim rpp’rpp:指定每页显示的记录条数,
dim pageno
i=1
rpp=50
pageno=cint(request("pageno"))
dim recordset1
dim recordset1_numrows
set recordset1 = server.createobject("adodb.recordset")
recordset1.activeconnection = mm_数据库名_string |||
recordset1.source = "select * from 表名 order by 编号 asc"
recordset1.cursortype = 1
recordset1.cursorlocation = 2
recordset1.locktype = 1
recordset1.open()
recordset1_numrows = 0
recordset1.pagesize=rpp
if pageno<=0 then pageno=1
if pageno>recordset1.pagecount then pageno=recordset1.pagecount
recordset1.absolutepage=pageno
sub showpageinfo(tpagecount,cpageno)
response.write "第"&cpageno&"页[共"&tpagecount&"页]"
end sub
sub showpagenavi(tpagecount,cpageno)
if cpageno<1 then cpageno=1
if tpagecount<1 then tpagecount=1
if cpageno>tpagecount then cpageno=tpagecount
dim navilength
navilength=20 ’navilength:显示的数字链接个数
dim i,startpage,endpage
startpage=(cpageno/navilength)*navilength 1
if (cpageno mod navilength)=0 then startpage=startpage-navilength
endpage=startpage navilength-1
if endpage>tpagecount then endpage=tpagecount
if startpage>1 then
response.write "<a class=""pagenavi"" href=""?pageno=" & (cpageno-navilength) & """><<</a> "
else
response.write "<font color=""#cccccc""><<</font> "
end if
for i=startpage to endpage
if i=cpageno then
response.write "<b>"&i&"</b>"
else
response.write "<a class=""pagenavi"" href=""?pageno=" & i & """>" & i & "</a>"
end if
if i<>tpagecount then response.write " "
next
if endpage<tpagecount then
response.write " <a class=""pagenavi"" href=""?pageno=" & (cpageno navilength) & """>>></a>"
else
response.write " <font color=""#cccccc"">>></font> "
end if
end sub
%>
新闻热点
疑难解答