分頁控制

 首先先讀取資料庫,並將查詢結果取出並集結

 

開啟數據庫部份……省略

 

將所有的資料集結到一個陣列變數中

sum = rs.recordcount ’錄資料查詢後的總筆數

field = Rs.fields.Count ’錄查詢後資料的總欄位數

 

redim theData(sum) ’告一陣列變數記錄每筆資料

redim thefield(field) ’告一陣列變數記錄每一欄位的記錄

 

’出所有查詢的資料並寫入變數中

for j = 0 to sum -1

            for i = 0 to field-1 ’得所有欄位資料

             thefield(i) = rs.fields(i).value

            next

            theData(j)=thefield ’所有欄位資料寫入一筆記錄中

            rs.movenext ’取下一筆數據

next

 

 

設定分頁

PageSize = 10 ’定每頁最大筆數

ingPage = 0 ’定起始頁 (頁碼是由0開始的,而流覽的頁碼則是從1開始)

 

function PageSet() 當網頁讀取結束後,就會開始執行

{

             取得總頁數

            PageCount = <%=PageCount%>

             取得目前所要顯示的頁碼  

              ingPage = <%=ingPage%>

 

                      利用迴圈產生所有的頁碼,並決定顯示與否

                        for (i = 0; i < PageCount; i++)

                        {

                                    if (i == ingPage)

                                    {

                                                theDataPage[i].style.visibility = "visible";

                                                document.thePage.NowPage.value = i+1;

                                    }

                                    else

                                    {

                                                theDataPage[i].style.visibility = "hidden";                                  

                                    }

                        }

 

 

 

}

function PageChange(PageNumber)

{

                    利用迴圈來達到頁面顯示的切換

                        for (i = 0; i < PageCount; i++)

                        {

                                    if (i == PageNumber)

                                    {

                                                theDataPage[i].style.visibility = "visible";

                                                document.thePage.NowPage.value = i+1;                                

                                    }

                                    else

                                    {

                                                theDataPage[i].style.visibility = "hidden";                                  

                                    }

                        }

 

}

function PageUp()

{

計算上一頁的頁碼,並將結果傳給頁面切換的函數來執行

            PageCount = <%=PageCount%>

            ingPage = <%=ingPage%>

            PageNumber = thePage.NowPage.value -2

            if (PageNumber < 0)

            {

                        PageNumber = 0

            }

            PageChange(PageNumber)

 

 

}

function PageDown()

{

計算下一頁的頁碼,並將結果傳給頁面切換的函數來執行

            PageCount = <%=int(PageCount)%>

            ingPage = <%=ingPage%>

            PageNumber = thePage.NowPage.value

            if (PageNumber >= PageCount)

            {

                        PageNumber = PageCount -1

            }

            PageChange(PageNumber)

 

}

顯示介面部份

 

首先先建立表單抬頭的欄位名稱部份

<table>

            <tr>

                        <td>Code</td>

                        <td>Name1</td>

                        <td>Name2</td>

                        <td>Name3</td>

            </tr>

</table>

 

利用雙迴圈來取得所有預存的資料庫資料,並以頁簽的方式來分類

<%

for j = 0 to sum -1

            if j mod PageSize = 0 then

                        response.write "<div id=’heDataPage’style=’osition:absolute; z-index:7; visibility: hidden;’"

                        response.write "<table>"

            end if

            response.write "<tr>"

            for i = 0 to field-1

                        response.write "<td>" & trim(theData(j)(i)) & "</td>"

            next

            response.write "</tr>"

            if j mod PageSize = PageSize-1 or j = sum-1 then

            response.write "</table>"

            response.write "</div>"

            end if

next

%>

 

建立所有的功能鍵

並以標籤的模式展示,利用left,top的設定來調整顯示的位置

<DIV ID="Tools" STYLE="position:absolute; left:10px; top:500px; visibility:visible">

<form name="thePage">

            <input type="button" οnclick="javascript:PageChange(’’" value="第一頁">

            <input type="button" οnclick="javascript:PageUp()" value="上一頁">

            <%for i = 0 to PageCount-1%>

                        <a href="javascript:PageChange(’%=int(i)%>’"><%=int(i)+1%></a>

            <%next%>

            <input type="button" οnclick="javascript:PageDown()" value="下一頁">

            <input type="button" οnclick="javascript:PageChange(%=int(PageCount-1)%>" value="最後一頁"><br>

            目前在第<input type="text" name="NowPage" size="2" maxlength="2" readonly>­頁/

            總共有<input type="text" name="PageCount" value="<%=PageCount%>" size="2" maxlength="2" readonly>­頁

</form>

 

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

andy3492

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值