ASP分页函数与应用

<!--#include file="../include/config.asp"-->
<%
'函数名称:ShowPage
'函数功能:显示分页的函数(和JoinChar函数一起使用)
'传递参数:sFileName,nTotalNum,nMaxPerPage,ShowTotal,ShowAllPages,strUnit
'          sFileName:文件名
'          nTotalNum:总记录数
'          nMaxPerPage:每页显示记录数
'          ShowTotal:是否显示总记录数
'          ShowAllPages:是否显示下拉框页数
'          strUnit:单位,如个,条,只,人
Function ShowPage(sFileName,nTotalNum,nMaxPerPage,ShowTotal,ShowAllPages,strUnit)
Dim n, i,strTemp,strUrl
If nTotalNum Mod nMaxPerPage=0 Then
     n= nTotalNum / nMaxPerPage
   Else
     n= nTotalNum / nMaxPerPage+1
   End If
   strTemp= "<table align=""center""><tr><td>"& vbCrLf
If ShowTotal=1 Then
strTemp=strTemp & "共 <font color=""#0000FF""><b>" & nTotalNum & "</b></font> " & strUnit & "&nbsp;&nbsp;&nbsp;"
End If
strUrl=JoinChar(sFileName)
   If Page<2 Then
     strTemp=strTemp & "首页 上一页&nbsp;"
   Else
strTemp=strTemp & "<a href=""" & strUrl & "page=1"">首页</a>&nbsp;"
strTemp=strTemp & "<a href=""" & strUrl & "page=" & (Page-1) & """>上一页</a>&nbsp;"
End If

   If n-Page<1 Then
     strTemp=strTemp & "下一页 尾页"
   Else
strTemp=strTemp & "<a href=""" & strUrl & "page=" & (Page+1) & """>下一页</a>&nbsp;"
strTemp=strTemp & "<a href=""" & strUrl & "page=" & n & """>尾页</a>"
   End If
    strTemp=strTemp & "&nbsp;页次:<strong><font color=""#FF0000"">" & Page & "</font>/" & n & "</strong>页 "
    strTemp=strTemp & "&nbsp;<b>" & nMaxPerPage & "</b>" & strUnit & "/页"& vbCrLf
If ShowAllPages=True Then
strTemp=strTemp & "&nbsp;转到:<select name=""page"" size=""1"" οnchange=""javascript:window.location='" & strUrl & "page=" & "'+this.options[this.selectedIndex].value;"">"& vbCrLf
For i = 1 To n  
   strTemp=strTemp & "<option value=""" & i & """"
   If cint(Page)=cint(i) Then strTemp=strTemp & " selected "
   strTemp=strTemp & ">第" & i & "页</option>"  
Next
strTemp=strTemp & "</select>"& vbCrLf
End If
strTemp=strTemp & "</td></tr></table>"& vbCrLf
Response.Write strTemp
End Function

'函数名称:JoinChar(和ShowPage函数一起使用)
'函数功能:自动获取参数,并在URL后连接?或&
'传递参数:strUrl:URL字符
Function JoinChar(strUrl)
If strUrl="" Then
JoinChar=""
exit function
End If
If InStr(strUrl,"?")<len(strUrl) Then
If InStr(strUrl,"?")>1 Then
   If InStr(strUrl,"&")<len(strUrl) Then
    JoinChar=strUrl & "&"
   Else
    JoinChar=strUrl
   End If
Else
   JoinChar=strUrl & "?"
End If
Else
JoinChar=strUrl
End If
End Function
%>
<link href="../CSS/default.css" rel="stylesheet" type="text/css">

<%
Dim page,i
i=1
Dim totalPut
Dim strFileName
Const MaxPerpage=10
strFileName="11.asp"
page=Trim(Request("page"))
If IsNumeric(page)=False Then page=1

rs.Open "select * from temp",conn,1,1
If Not rs.Eof Then
totalPut=rs.recordcount
if (page-1)*MaxPerpage>totalput then
   if (totalPut mod MaxPerpage)=0 then
    page= totalPut / MaxPerpage
   else
    page= totalPut / MaxPerpage + 1
   end if
end if
if page=1 then
   Call MainInfo()
else
   if (page-1)*MaxPerpage<totalPut then
    rs.move (page-1)*MaxPerpage
    dim bookmark
    bookmark=rs.bookmark
    Call MainInfo()
   else
    page=1
    Call MainInfo()
   end if
end if
End If
rs.Close
Set rs=Nothing
%>
<%Sub MainInfo()%>
<table width="200" border="0" align="center">
<tr>
    <td>id</td>
    <td>学号</td>
    <td>学分</td>
</tr>
<tr>
<%Do While Not rs.Eof%>
    <td><%=rs("id")%></td>
    <td><%=rs("code")%></td>
    <td><%= rs("name") %></td>
</tr>
<%
i=i+1
If i>MaxPerPage Then Exit Sub
rs.MoveNext
Loop
%>     
</table>
<p>
   <%End Sub%>
   <%
If totalput>0 Then
call showpage(strFileName,totalput,MaxPerPage,false,true,"条新闻")
End If
%>
</p>
<p>&nbsp; </p>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值