分頁控制

类别:Asp 点击:0 评论:0 推荐:

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

 

開啟數據庫部份……省略

 

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

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" onclick="javascript:PageChange(’’" value="第一頁">

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

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

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

            <%next%>

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

            <input type="button" onclick="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>

 

本文地址:http://com.8s8s.com/it/it9143.htm