+------------------------------------------------------------------------------------------------------+
敝帚自珍:ASP数据分页类Pager [2005-10-19] Xmercy 发表在 Develop
| <% Class Pager
Private IUrl Private IPage Private IParam Private IPageSize Private IPageCount Private IRecordCount Private ICurrentPageIndex
Public Property Let Url(ByVal PUrl) IUrl = PUrl End Property
Public Property Get Url() If IUrl = "" Then If Request.QueryString <> "" Then Dim query For Each key In Request.QueryString If key <> Param Then query = query & key & "=" & Server.UrlEnCode(Request.QueryString(key)) & "&" End If Next IUrl = Page & "?" & query & Param & "=" Else IUrl = Page & "?" & Param & "=" End If End If Url =IUrl End Property
Public Property Let Page(ByVal PPage) IPage = PPage End Property
Public Property Get Page() Page = IPage End Property
Public Property Let Param(ByVal PParam) IParam = PParam End Property
Public Property Get Param() Param = IParam End Property
Public Property Let PageSize(ByVal PPageSize) IPageSize = PPageSize End Property
Public Property Get PageSize() PageSize = IPageSize End Property
Public Property Get PageCount() If (Not IPageCount > 0) Then IPageCount = IRecordCount \ IPageSize If (IRecordCount MOD IPageSize) > 0 Or IRecordCount = 0 Then IPageCount = IPageCount + 1 End If End If PageCount = IPageCount End Property
Public Property Let RecordCount(ByVal PRecordCount) IRecordCount = PRecordCount End Property
Public Property Get RecordCount() RecordCount = IRecordCount End Property
Public Property Let CurrentPageIndex(ByVal PCurrentPageIndex) ICurrentPageIndex = PCurrentPageIndex End Property
Public Property Get CurrentPageIndex() If ICurrentPageIndex = "" Then If Request.QueryString(Param) = "" Then ICurrentPageIndex = 1 Else If IsNumeric(Request.QueryString(Param)) Then ICurrentPageIndex = CInt(Request.QueryString(Param)) If ICurrentPageIndex < 1 Then ICurrentPageIndex = 1 If ICurrentPageIndex > PageCount Then ICurrentPageIndex = PageCount Else ICurrentPageIndex = 1 End If End If End If CurrentPageIndex = ICurrentPageIndex End Property
Private Sub Class_Initialize() With Me .Param = "page" .PageSize = 10 End With End Sub
Private Sub Class_Terminate() End Sub
Private Function Navigation() Dim Nav If CurrentPageIndex = 1 Then Nav = Nav & " 首页 上页 " Else Nav = Nav & " <a href=""" & Url & "1"">首页</a> <a href=""" & Url & (CurrentPageIndex - 1) & """>上页</a> " End If
If CurrentPageIndex = PageCount Or PageCount = 0 Then Nav = Nav & " 下页 尾页 " Else Nav = Nav & " <a href=""" & Url & (CurrentPageIndex + 1) & """>下页</a> <a href=""" & Url & PageCount & """>尾页</a> " End If
Navigation = Nav End Function
Private Function SelectMenu() Dim Selector Dim i : i = 1 While i <= PageCount If i = ICurrentPageIndex Then Selector = Selector & "<option value=""" & i & """ selected=""true"">" & i &"</option>" & vbCrLf Else Selector = Selector & "<option value=""" & i & """>" & i &"</option>" & vbCrLf End If i = i + 1 Wend SelectMenu = vbCrLf & "<select style=""font:9px Tahoma"" onchange=""location='" & Url & "' + this.value"">" & vbCrLf & Selector & vbCrLf & "</select>" & vbCrLf End Function
Public Sub Display() If RecordCount > 0 Then %> <style>b{font:bold}</style> <div style="text-align:right;width:100%">>>分页 <%=Navigation()%> 页次:<b><%=ICurrentPageIndex%></b>/<b><%=PageCount%></b>页 <b><%=PageSize%></b>个记录/页 转到<%=SelectMenu()%>页 共 <b><%=IRecordCount%></b>条记录</div> <% Else Response.Write("<div style=""text-align:center"">暂无记录</div>") End If End Sub
End Class %> | |
+------------------------------------------------------------------------------------------------------+ |