【asp.net】asp access 大数据量的分页的方法

更新时间:2016-07-13    来源:Access    手机版     字体:

【www.bbyears.com--Access】

"本款分页效果支持"分页,分页效果:首页 上一页 ... 2 3 4 5 6 7 ... 下一页 最后一页这种分页模式,有论坛风格
"id title content status updatetime
"1 t1 c1 1 2010-5-26 21:16:06
"2 t2 c2 1 2010-5-26 21:16:09
"3 t3 c3 1 2010-5-26 21:16:12
"4 t4 c4 1 2010-5-26 21:16:15
"5 t5 c5 1 2010-5-26 21:16:23


DB="database/db1.mdb"
path=Server.MapPath(DB)
set conn=server.createobject("adodb.Connection")
connstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source="&path
conn.Open connstr
Set rs=server.CreateObject("adodb.recordset")


%>




 
  New Document
 
 
  words" CONTENT="">
 
 
 

 
 

 
 
  ID
  标题
  时间  
 
 <%
 "十万条以上数据的分页的方法
 "作者:wangsdong
 "来源:111cn.net
 "原创文件,转载请保留此信息,谢谢
keyword=request("keyword")
page=request("page")
If page="" Or Not IsNumeric(page) then page=1 Else page=CInt(page)
page_size=2
q1=" and status>0"
If keyword<>"请输入关键词" and keyword<>"" then
 q1=q1&" and title like "%"&keyword&"%""
end If
if page>1 then
 sql="select top "&page_size&" id,title,content,updatetime from news where 1=1 and id<(select min(id) from (select top "&(page-1)*page_size&" id from news where status>0"&q1&" order by id desc) as c1)" 
else  
 sql="select top "&page_size&" id,title,content,updatetime  from news where 1=1"  
end if
sql=sql&q1&" order by id desc" 
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.eof then
 do while not rs.eof
 id=rs("id")
 title=rs("title")
 content=rs("content")
 updatetime=rs("updatetime")
 "*************循环的内容开始************************
 %>
 
  <%=id%>
  <%=title%>
  <%=updatetime%>  
 
 <%
 "*************循环的内容结束************************
 rs.movenext
 loop
end if
rs.close
%>

<%
"分页开始
"计算总页数
page_count=1
sql="select count(*) as t from news where 1=1"&q1
rs.open sql,conn,1,1
if rs.eof then
else
 recordset_count=rs("t")
 if recordset_count mod page_size=0 then
  page_count=recordset_countpage_size
 else
  page_count=recordset_countpage_size+1
 end if
end if
rs.close
"分页,分页效果:首页 上一页 ... 2 3 4 5 6 7 ... 下一页 最后一页
if page=1 then
 response.write "首页 上一页 "
else
 response.write "首页 上一页 "
end if
if page>4 then
 s=page-3
 response.write "..."
else
 s=1   
end if  
if page<=page_count-3 then
 e=page+3    
else
 e=page_count   
end if   
for i=s to e
 if i=page then
  response.write ""&i&" "
 else
  response.write ""&i&" "
 end if  
next

if page  response.write "..."
end if
if page=CInt(page_count) then
 response.write "下一页 最后一页"
else
 response.write "下一页 最后一页"
end if 

%>

 
 
 

本文来源:http://www.bbyears.com/shujuku/25303.html

猜你感兴趣