大量记录快速分页代码,SQL语句分页
<%Cardnumber = Conn.Execute("select count(*) as counts from [List_view]")("counts")
vPage = Cint(Request.QueryString("Page"))
vPageSize = 50
If Cardnumber mod vPageSize > 0 Then
vPgnum = Cint(Fix(Cardnumber/vPageSize) + 1)
Else
vPgnum = Cint(Cardnumber/vPageSize)
End If
If vPage = "" Or vPage < 1 Then vPage = 1
If vPage > vPgnum Then vPage = vPgnum
vPagecount = vPageSize*(vPage-1)
Set vRs = Server.CreateObject("ADODB.Recordset")
If vPage = 1 Then
Sql = "select top "&vPageSize&" id from [List_view] order by id"
Else
Sql = "select top "&vPageSize&" id from [List_view] where (id not in (select top "&vPagecount&" id from [List_view] order by id)) order by id"
End If
vRs.Open Sql,conn,1,1
If vRs.Eof Then
Response.Write("暂无数据~~~")
Else
Do While Not vRs.Eof
Response.Write(""&vRs("id")&"<br />")
vRs.MoveNext
Loop
vRs.close:Set vRs = Nothing
End If
'---------------------分页开始------------------------
If Cardnumber > vPageSize Then
Response.Write " <div id=""Main_ShowPage"">" & Chr(13)
if AllPage > vPgnum then
AllPage = vPgnum
end if
if vPage - FrontPage < 1 then
Start = 1
sEnd = AllPage
elseif vPage + AllPage - FrontPage > vPgnum then
Start = vPgnum - AllPage + 1
sEnd = vPgnum
else
Start = vPage - FrontPage
sEnd = vPage - FrontPage + AllPage - 1
end if
for i = Start to sEnd
if i = 1 then
Url = "1"
else
Url = i
end if
if i = vPage then
vPages = vPages & "<font color=""#ff0000""><b>["&i&"]</b></font> "
else
vPages = vPages & "<a href=""?Page="&Url&""">["&i&"]</a> "
end if
next
if vPage = 1 then
Fpage = "首页"
Lpage = "上一页"
else
Fpage = "<a href=""?Page=1"">首页</a>"
Lpage = "<a href=""?Page="&vPage - 1&""">上一页</a>"
end if
if vPage = vPgnum then
Npage = "下一页"
Rpage = "尾页"
else
Npage = "<a href=""?Page="&vPage + 1&""">下一页</a>"
Rpage = "<a href=""?Page="&vPgnum&""">尾页</a>"
end if
Response.Write "共"&Cardnumber&"条记录 页次:"&vPage&"/"&vPgnum&"页 "&Fpage&" "&Lpage&" "&vPages&" "&Npage&" "&Rpage&" "
Response.Write "<select name=""page"" onChange=javascript:location.href=""?Page=""+document.all.page.options[document.all.page.selectedIndex].value+"""" size=""1"">"
for i = 1 to vPgnum
Response.Write " <option value="""&i&""" "
if vPage = i then Response.Write "selected"
Response.Write ">第"&i&"页</option>"
next
Response.Write "</select>"
Response.Write " </div>" & Chr(13)
End If
'---------------------分页结束------------------------
%>
[[it] 本帖最后由 zhangyao3287 于 2008-6-6 11:14 编辑 [/it]]