首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CGI >

asp分页展示

2013-01-01 
asp分页显示分页显示怎么用啊,最好能有代码详解一下,谢谢[解决办法]%Dim DataCount记录总数Dim MaxPerPa

asp分页显示
分页显示怎么用啊,最好能有代码详解一下,谢谢
[解决办法]

<%
Dim DataCount'记录总数
Dim MaxPerPage'每页条数
Dim PageCount'总页数
Dim Page'页码
Dim PerPageNum '每页显示的分页页码数量=PerPageNum*2+1
Dim MaxPageNum '每页显示的分页的最大页码
Dim MinPageNum '每页显示的分页的最小页码
Dim DataTable'数据表名
Dim PageUrl'本页地址


PerPageNum=2
Page=Clng(Request("Page"))
MaxPerPage=32
DataTable="tb"
PageUrl =Request.ServerVariables("Path_Info")
Taxis=" Order By id"

Set Rs=Server.CreateObject("ADODB.Recordset")
StrSQL="Select ID From "&DataTable&Taxis
Rs.open StrSQL,DbConn,1,1

DataCount=Rs.RecordCount

If(DataCount>0) Then'如果记录总数=0,则不处理
If(DataCount Mod MaxPerPage=0)Then'如果记录总数除以每页条数有余数,则=记录总数/每页条数+1
PageCount=Int(DataCount/MaxPerPage)'获取总页数
Else
PageCount=Int(DataCount/MaxPerPage)+1'获取总页数
End If

'获取本页需要用到的id============================================
'读取所有记录的id数值,因为只有id所以速度很快

   Rs.PageSize = MaxPerPage '每页显示记录数
   If Page<1 Then Page = 1
   If Page>PageCount Then Page = PageCount
   If PageCount> 0 Then Rs.absolutepage = Page  

For I=1 To Rs.PageSize
If Rs.EOF Then Exit For  
If(I=1)Then
ID=Rs("ID")
Else
ID=ID &","&Rs("ID")
End If
Rs.MoveNext
Next
'获取本页需要用到的id结束============================================
End If

Rs.Close
%>



然后在要分页的地方调用下面这个过程

<%Sub ShowPage()%> 
<table width="100%" border="0" cellpadding="1" cellspacing="0">
<form method="post" onSubmit="return false;">
  <tr> 
      <td align="center">共<b><%=DataCount%></b>条信息 <b><%=MaxPerPage%></b>条/页 
        共<b><%=PageCount%></b>页</td>
    <td align="right"> 
      <%
'设置分页页码开始===============================
MinPageNum=Page-PerPageNum'计算页码开始值
MaxPageNum=Page+PerPageNum'计算页码结束值

If(MinPageNum<1) Then'如果页码开始值小于1则=1
    MinPageNum=1
    MaxPageNum=PerPageNum*2+1
End if

If(Page>1) Then'如果页码大于1则显示(第一页)
response.write ("<a href='"& PageUrl &"?Page=1"&url&"' class='Black'>首页</a>&nbsp;")
End If

If(Page>1) Then'如果页码开始值大于1则显示(更前)
response.write ("<a href='"& PageUrl &"?Page="& Page-(1) &url&"' class='Black'>上页</a>&nbsp;")
End If

If(MaxPageNum>PageCount) Then'如果页码结束值大于总页数,则=总页数
If MinPageNum>1 Then
MinPageNum=PageCount-(PerPageNum*2)
If MinPageNum<1 Then
MinPageNum=1
End If
End If
    MaxPageNum=PageCount
End If

For i = MinPageNum To MaxPageNum'循环输出页码
    If(i=Page) Then
Response.Write ("<strong>"& i &"</strong>&nbsp;")
    Else


Response.Write ("<a href="& PageUrl &"?Page="& i &url&" class='Black'>["& i &"]</a>&nbsp;")
    End If
Next

If(Page<PageCount) Then'如果页码结束值小于总页数则显示(更后)
Response.Write ("<a href='"& PageUrl &"?Page="& Page+(1) &url&"' class='Black'>下页</a>&nbsp;")
End If

If(Page<PageCount) Then'如果页码小于总页数则显示(最后页)
Response.Write ("<a href='"& PageUrl &"?Page="& PageCount &url&"' class='Black'>尾页</a>&nbsp;")
End If
'设置分页页码结束===============================
%>
      直接到 </td>
    <td width="30" align="center"> 
      <input name="Page" type="text" value="<%=Page%>" size="3" onKeyDown='if (event.keyCode==13) window.location.href="<%=PageUrl%>?Page="+ this.form.Page.value+"<%=Url%>";' class="BlueInput">
    </td>
      <td width="12" align="center">页</td>
    <td width="44" align="center"> 
      <input type="Button" name="GoPage" value="前往" onClick='window.location.href="<%=PageUrl%>?Page="+ this.form.Page.value+"<%=Url%>";'>
    </td>
  </tr>
  </form>
</table>
<%End Sub%>

热点排行