VB 版 (精华区)

发信人: folmorse (◆金瓶楼主◆), 信区: VB
标  题: 使用ASP+VBscript访问数据库,怎么实现翻页
发信站: 大红花的国度 (Sun Jun 11 15:13:51 2000), 转信

发信人: pihy (飘雪~~随风零舞却为谁?), 信区: WWW
标  题: Re: 使用ASP+VBscript访问数据库,怎么实现翻页?
发信站: BBS 水木清华站 (Fri Nov  6 14:59:32 1998)
【 在 pihy (飘雪~~随风零舞却为谁?) 的大作中提到: 】
: 我提供一个实现此功能的模板,它还可以实现在输入框任意页,按下“跳转”按钮后
: 可以跳转到所需的页中去。适用于IE,若想用于NETSCAPE,稍作改动就行了。
: <%@ Language=VBScript %>
: <html>
: <head>
: <Script Language="VBScript">
: <!--
: Function ChgPage_OnSubmit()
:          IF Trim(ChgPage.GotoPage.Value)<>"" Then
:                  If Not IsNumeric(ChgPage.GotoPage.Value) Then
:                          ChgPage_OnSubmit=False
:                          Msgbox "页码必须是数字!",vbCritical,"页码错"
:                          ChgPage.GotoPage.Focus()
:                  Else
:                          ChgPage_OnSubmit=True
:                  End If
:          Else
:                  ChgPage_OnSubmit=False
:                  Msgbox "请填入页码!",vbCritical,"页码错"
:                  ChgPage.GotoPage.Focus()
:          End If
: End Function
: -->
: </Script>
: <title></title>
: </head>
: <body bgcolor="#FFFFFF">
: <table border="2" width="100%" cellspacing="0" cellpadding="2">
:    <tr>
:   <!-- 此处为你的报表标题,可以自行更改 -->
:      <td width="40%"><p align="center"></td>
:      <td width="20%"><p align="center"></td>
:      <td width="40%"><p align="center"></td>
:    </tr>
: <%      On Error Resume Next
:          Dim PageNo
:          Set DBCon=Server.CreateObject("ADODB.Connection")
:      '此处为你的数据库连接语句
:      ConnectionString=""
:          DBCon.Open ConnectionString
:      '此处加入你的SQL语句
:          strSql=""
:          Set oRs = Server.CreateObject("ADODB.Recordset")
:          ' Determine what PageNumber the scrolling currently is on
:          Mv = Request("Mv")
:          If Trim(Request.Form("PageNo")) = "" Then
:               PageNo = 1
:          Else
:               PageNo = Cint(Request.Form("PageNo"))
:          End If
:          oRs.Open strSql, DBCon, 3
:          '3-----adOpenStatic
:          '一页处理八条记录
:          oRs.PageSize =8
:          ' Adjust PageNumber as Appropriate
:          Select Case Mv
:                Case "首  页"
:                                  PageNo=1
:                Case "上一页"
:                     If PageNo > 1 Then
:                          PageNo = PageNo - 1
:                     Else
:                          PageNo = 1
:                     End If
:                Case "下一页"
:                     If oRs.AbsolutePage <  oRs.PageCount Then
:                          PageNo = PageNo + 1
:                     Else
:                          PageNo = oRs.PageCount
:                     End If
:                Case "末  页"
:                     PageNo=oRs.PageCount
:                Case "跳  转"
:                     PageNo=CInt(Request("GotoPage"))
:                     If PageNo<1 Then
:                          PageNo=1
:                     ElseIf PageNo>oRs.PageCount Then
:                          PageNo=oRs.PageCount
:                     End If
:                Case Else
:                     PageNo = 1
:         End Select
:     oRs.AbsolutePage = PageNo
:          For j=1 to oRs.PageSize
: %>
:    <tr>
:      <td width="40%"><p align="center">
: <%  '在此处加入你想要的当前记录的字段  %>
:      </td>
:      <td width="20%"><p align="center">
: <%  '在此处加入你想要的当前记录的字段  %>
:      </td>
:      <td width="40%"><p align="center">
: <%  '在此处加入你想要的当前记录的字段  %>
:      </td>
:    </tr>
: <%
:                  oRS.MoveNext
:                  If oRs.Eof Then
:                          Exit For
:                  End If
:          Next
: %>
: </table>
: <form Action="" Method="POST" Name="ChgPage">
        对不起,这儿漏了一句:<Input type="hidden" name="PageNo" value="
<%=PageNo%>">
:                  <!--  Only show appropriate buttons -->
: <table border="0" width="100%" style="font-family: 宋体; font-size: 12pt"
: cellspacing="0" cellpadding="0">
: <tr>
: <td Width=15%>
:                  <%   If PageNo > 1 Then %>
: <Input Type="Submit" Name="Mv" Value="首  页"
: style="font-family: 宋体; font-size: 12pt">
:                  <%   End If %>
: </td><td width=15%>
:                  <%   If PageNo > 1 Then %>
: <INPUT TYPE="Submit" Name="Mv" Value="上一页"
: style="font-family: 宋体; font-size: 12pt">
:                  <%   End If %>
: </td><td width=15%>
:                  <%   If PageNo <   oRs.PageCount Then %>
: <INPUT TYPE="Submit" Name="Mv" Value="下一页"
: style="font-family: 宋体; font-size: 12pt">
:                  <%   End If  %>
: </td><td width=15%>
:                  <%   If PageNo <   oRs.PageCount Then %>
: <Input Type="Submit" Name="Mv" Value="末  页"
: style="font-family: 宋体; font-size: 12pt">
:                  <%   End If %>
: </td>
: <td width=40% align=right>
: <%
: If oRs.PageCount>1 Then
:          Dim nLen
:          nLen=Log(10*(oRs.PageCount+1)) / Log(10)
: %>
: 位置:<Input type="Text" Name="GotoPage" Size=<%=nLen%> MaxLength=<%=nLen%>
: style="text-align:right;font-family: 宋体; font-size: 12pt" Value=<%=PageNo%>
: align=right>/<%=oRs.PageCount%>
: <Input type="Submit" Name="Mv" Value="跳  转"
: style="font-family: 宋体; font-size: 12pt">
: <% End If %>
: </td>
: </tr>
: </table>
: </form>
: </body>
: </html>
--
※ 修改:.folmorse 于 Jun 11 15:12:43 修改本文.[FROM: hpwei.hit.edu.cn]
--
※ 转寄:.华南网木棉站 bbs.gznet.edu.cn.[FROM: hpwei.hit.edu.cn]

--
☆ 来源:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: folmorse.bbs@melon.g]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.463毫秒