Asp 翻页解决方案

    Asp 翻页是web开发必须的一个功能,下面代码是翻页功能的一个公共方法,可以在每个页面中直接引入。
此页面会显示一个翻页的功能条。此功能使用了一个page的变量来保存当前页号,使用时请注意不要修改。

<script language="javascript">
function JumpPage(thispage){
 document.forms[0].action = thispage;
 document.forms[0].submit();
}
</script>
<%
'获取页面数量
function GetPage()
 GetPage = request("Page")
 if GetPage = "" OR GetPage<1 then
  GetPage = 1
 else
  GetPage = cint(GetPage)
 end if
end function
'设置 翻页
function SetAbsPage(ByRef RetRs)
 if RetRs is nothing then
  SetAbsPage = false
  exit function
 end if
 
 if RetRs.Recordcount <= 0 then
  SetAbsPage = true
  exit function
 end if
 
 Dim iPageSize
 iPageSize =Cint(10)          '每页记录数量,可修改

 RetRs.PageSize = Cint(iPageSize)
 iAbsPage = Cint(GetPage())
 
 if iAbsPage > RetRs.PageCount then iAbsPage = RetRs.PageCount
 
 RetRs.AbsolutePage = Cint(iAbsPage)
 
 if RetRs.AbsolutePage > 0 then
  SetAbsPage = true
 else
  SetAbsPage = false
 end if
end function

'生成翻页的功能条
function PageBar(PageNum,Url)
 Dim PageUrl,NowNum,FirstPage,PrewPage,NextPage,LastPage,PageSelect
 NowNum = GetPage()
 if Trim(Url) = "" then
  PageUrl = Request.ServerVariables("SCRIPT_NAME") & "?"  
 else
  if InStr(Url,"?") > 0 then
   if Right(Trim(Url),1) = "&" then
    PageUrl = Trim(Url)
   else
    PageUrl = Trim(Url) & "&"
   end if
  else
   PageUrl = Trim(Url) & "?"
  end if
 end if
 
 if NowNum <= 1 then
  FirstPage=""
  PrewPage = ""
 else
  FirstPage = "href='#' onClick=javascript:JumpPage('"& PageUrl &"Page=1');"
  PrewPage = "href='#' onClick=javascript:JumpPage('"& PageUrl &"Page="& NowNum-1 &"');"
 end if
 if cint(NowNum) >= cint(PageNum) then
  NextPage = ""
  LastPage = ""  
 else
  NextPage = "href='#' onClick=javascript:JumpPage('"& PageUrl &"Page="& NowNum+1 &"');"
  LastPage = "href='#' onClick=javascript:JumpPage('"& PageUrl &"Page="& PageNum &"');"
 end if
 PageSelect = "" 
 for i = 1 to PageNum
  if i = NowNum then
   PageSelect = PageSelect & "<option value='" & PageUrl & "Page=" & i & "' selected>" & i & "</option>/n"
  else
   PageSelect = PageSelect & "<option value='" & PageUrl & "Page=" & i & "'>" & i & "</option>/n"
  end if
 next
 PageBar = ""
 PageBar = PageBar & "<table border='0' width='98%' align='center'><tr><td align='right'>"
 PageBar = PageBar & "<label class='body'>Total <span class='bodyred'>" & PageNum & "</span> pages,"
 PageBar = PageBar & "Now is <span class='bodyred'>" & NowNum & "</span>&nbsp; &nbsp;"
 PageBar = PageBar & "<span class='bodylink'>"
 PageBar = PageBar & "[<a class='bodylink'" & FirstPage & ">First</a>/"
 PageBar = PageBar & "<a class='bodylink'" & PrewPage & ">Prew</a>]"
    PageBar = PageBar & "[<a class='bodylink'" & NextPage & ">Next</a>/"
 PageBar = PageBar & "<a class='bodylink'" & LastPage & ">Last</a>]"
 PageBar = PageBar & "</span>Jump to "
 PageBar = PageBar & "<select name='SelJumpTo' onChange='javascript:JumpPage(this.value);'>" & PageSelect & "</select>"
 PageBar = PageBar & "</label></td></tr></table>"
end function %>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值