通用的asp分页函数代码asp

/ / 2016-07-24   阅读:2488
这是我asp程序中最常用,最通用的一个asp分页函数,适合所有表,在整个网站的开发过程中,只用这一个就可以解决所有分页问题,并且允许带入不同的参数。'功能:常用的asp分页函数 '开发:<a href=&...

这是我asp程序中最常用,最通用的一个asp分页函数,适合所有表,在整个网站的开发过程中,只用这一个就可以解决所有分页问题,并且允许带入不同的参数。

'功能:常用的asp分页函数
'开发:<a href="http://www.aspbc.com">www.aspbc.com</a> '作者:wangsdong
'原创文章,转载请保存此信息 
'参数含义:
'page当前页
'page_size每页总数
'recordset_count总数
'str字符串
Function fpage(page,page_size,recordset_count,str)
If recordset_count=0 Or IsNull(recordset_count) Then Exit function
If str<>"" then
 s=Split(str,"|")
 s2=""
 For i=0 To UBound(s)
   s2=s2&"&"&s(i)&"="&server.URLEncode(request(s(i)))
 Next
End If
Dim str9
str9=""
page=CInt(page)
 if recordset_count mod page_size=0 then 
  page_count=recordset_count\page_size
 else
  page_count=recordset_count\page_size+1
 end if

str9=str9&"<a href=""?page=1"&s2&""">首页</a> "
if page>4 then 
 s=page-3
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
  str9=str9&"<b>"&i&"</b> "
 else
  str9=str9&"<a href=""?page="&i&s2&""">"&i&"</a> "
 end if  
Next

  str9=str9&"<a href=""?page="&page_count&s2&""">末页</a> <span>第 (<span class=""cRed"">"&page&"</span>/<span class=""cTotal"">"&page_count&"</span>) 页</span>"
  fpage=str9
End Function


使用方法
1、分页不需要参数

'先得到符合条件的记录总数
'地址如:http://www.aspbc.com/list.asp 后面没有参数
sql="select count(*) as num from table where ……"
countnum=conn.execute(sql)
'然后调用这个函数
page=request("page") ’得到当前页数
if page="" then page=1 
page_size=10 '当前每页10条
str=""   '不传参数,也就是地址栏没有参数
'调用函数
response.write fpage(page,page_size,count,str)


2、分页需要参数

'先得到符合条件的记录总数
'地址如:http://www.aspbc.com/list.asp?classid=1&cid=2
'后面有classid和cid两个参数
sql="select count(*) as num from table where ……"
countnum=conn.execute(sql)
'然后调用这个函数
page=request("page") ’得到当前页数
if page="" then page=1 
page_size=10 '当前每页10条
str="classid|cid"   '传参数,也就是地址栏有参数
'调用函数
response.write fpage(page,page_size,count,str)


我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈