七彩课堂[网页设计ASP.NET教程系列]
做Asp的时候最烦分页的问题
   我们在做Asp的时候最烦分页的问题了...简单的上下翻页又不能满足要求. 网上有很多分页类..不太好用..考虑到自己会经常用到..所以写了个简单易用的分页类..
Class Offset
Private oConn,oRs,curPage,Sql,pSize,Questr,Script_Name

Private Sub Class_Initialize
If Request("page")="" Or Request("page")<1 Then
curPage=1
Else
curPage=Request("page")
End If
Script_Name = request.ServerVariables("SCRIPT_NAME")
Questr = request.ServerVariables("QUERY_STRING")
If Instr(Questr,"page=")<>0 Then
Pos = Instr(Questr,"page=")
delStr = mid(Questr,Pos,len(Questr)-Pos+1)
Questr = Replace(Questr,delStr,"")
If Questr ="" Then
Questr = "?"
Else
Questr = "?"&Questr
End If

Else
If Instr(Questr,"?")=0 And Questr<>"" Then
Questr = "?"&Questr&"&"
Else
Questr = "?"
End If
End If
Questr = Script_Name&Questr

End Sub

Public Property Let setConn(objConn)
oConn=objConn
End Property

Public Property Let setSql(Sql_Str)
Sql=Sql_Str
End Property

Public Property Let PageSize(num)
pSize=num
End Property

Public Property Get PageSize()
If pSize="" And Not IsNumeric(pSize) Then
PageSize=5
Else
PageSize=pSize
End If
End Property

Public Property Get GetRs()
Set oRs=Server.createObject("ADODB.RecordSet")
oRs.Open Sql,oConn,1,1
oRs.PageSize = PageSize
If Not oRs.Eof Then
If curPage>oRs.PageCount Then
oRs.AbsolutePage = curPage
End If
If curPage<=0 Then
oRs.AbsolutePage = 1
End If
End If
Set GetRs = oRs
End Property

Function list_offset()


A =1
B =1
Fsize =5 //分页显示数量 1 2 3 4 5 6
Maxsize=GetRs.PageCount

Npage =Int(curPage/Fsize)+1

A =Fsize*Npage-Fsize+1
B =Fsize*Npage

If curPage--1=A Then
Npage =Npage-1
A =Fsize*Npage-Fsize+1
B =Fsize*Npage
End If

If curPage-1=B Then
Npage =Npage+1
A =Fsize*Npage-Fsize+1
B =Fsize*Npage
End If

If B>=Maxsize Then
A =Maxsize-Fsize--1
B =Maxsize
End If

If Maxsize<Fsize Then
A =1
B =Maxsize
End If

For i=A To B
link=link&"<a href='"&Questr&"page="&i&"'>["&i&"]</a> "
Next
If B=0 Then
link="<a href='#'>.No Data!.</a>"
Else
Prev =A-1
Nex =B--1

If Prev=0 Then
Prev=1
End If

If Nex>Maxsize Then
Nex=Maxsize
End If

first = 1
last = Maxsize
link = "<a href='"&Questr&"page="&first&"'><font face='webdings'>9</font></a> <a href='"&Questr&"page="&Prev&"'><font face='webdings'>7</font></a> "&link&"<a href='"&Questr&"page="&Nex&"'><font face='webdings'>8</font></a> <a href='"&Questr&"page="&last&"'><font face='webdings'>:</font></a> <font class='font-12'>["&curPage&"/"&Maxsize&"]</a>"
End If
list_offset = link
End Function

End Class

实例演示:
Set ofset = new offset
oClass.setConn = conn /设置数据库连接..
oClass.setSql = "select * from table "/设置查询语句..
Set rs = oClass.GetRs() //生成数据集..

oClass.PageSize = 15 /每页显示记录数..
-----------------------------------------------------------------------------
do while not rs.eof
response.write(rs("title"))
rs.movenext
loop
---------------------------------------------------------------
<%=OClass.list_offset()%>//调用分页数组...

 
信息推荐
资讯中心 | 电子商务 | 搜索营销 | 设计学院 | 中医养生 | 养生保健 | 节日祝福 | 民俗文化 | 奇闻趣事
建站知识 | 人世百态 | 网站导航 | 传统节日 | 搜索热点 | 星座运势 | 趣闻轶事 | 祝福的话 | 短信大全
© 2023 QicaiSpace.Com