程序代碼 <% '//分頁函數 '//psize:每頁顯示的數據數 '//pindex:當前頁碼 '//tbName:表名 '//keyIndex:根據什么字段分頁,一般是自增長類型(access數據庫的自動編號) '//where:查詢條件 '//order:排序條件,缺省為" order by " &keyIndex &" desc" '//總記錄數與總頁數可從返回的結果集中直接獲取,字段datacount存儲總記錄數,字段pagecount存儲總頁數 PRivate pindex,datacount,pages 'datacount = 0 'pages = 1 public function changePage(psize,tbName,keyIndex,where,order) dim sqlstring pindex = Trim(Request.QueryString("page")) if not isnumeric(psize) or psize="" then psize=1'//每頁顯示的數據數 if not isnumeric(pindex) or pindex="" then pindex=1'//當前頁碼 if order="" then order=" order by " & keyIndex & " desc" '//獲取總數據數 'dim datacount,pages set rs=conn.execute("select count(*) as datacount from " & tbName & " where 1=1 " & where) datacount = rs("datacount")'//總記錄數 rs.close set rs=nothing '//計算總頁數 if (datacount mod psize)=0 then pages=datacount / psize else pages=datacount / psize + 1 end if '// if cint(pindex)>pages then pindex=pages '拼接sql字符串 if pindex<=1 then sqlstring="select top " & psize & " *," & datacount & " as datacount," & pages & " as pagecount from " &_ tbName & " where 1=1 " & where & " " & order else sqlstring="select top " & psize & " *," & datacount & " as datacount," & pages & " as pagecount from " &_ tbName & " where 1=1 and " & keyIndex & " not in(select top " & (pindex-1)*psize & " " & keyIndex & " from " &_ tbName & " where 1=1 " & where & " " & order & ") " & where & " " & order end if 'Response.Write(sqlstring) set changePage=conn.execute(sqlstring) end function '//分頁導航 '//fileName:文件名/當前頁面的話,可以留空 '//argString:分頁參數例如classid=1&tid=16,分頁必須的參數page不必填寫 '//pindex:當前頁碼 '//datacount:總記錄數 '//pages:總頁數 '//showMsg:是否顯示分頁信息,參數為true/false '//showText:是否顯示首頁、上頁、下頁、末頁的導航,參數為true/false '//showNumber:是否顯示數字分頁導航,參數為true/false 'public function pageLink(fileName,argString,pindex,datacount,pages,showMsg,showText,showNumber) public function pageLink(fileName,argString,showMsg,showText,showNumber) '// if argString<>"" then argString = argString & "&" if not showText and not showNumber then showText=true '// if showMsg then Response.Write("[") Response.Write("第 <span style='color:red;'>" & pindex & "</span> 頁") Response.Write("/分 <span style='color:red;'>" & pages & "</span> 頁") Response.Write("/總 <span style='color:red;'>" & datacount & "</span> 條記錄") Response.Write("] ") end if '// if showText then if pindex>1 then Response.Write("<a href='" & fileName & "?" & argString & "page=1'>[首頁]</a>") Response.Write(" ") Response.Write("<a href='" & fileName & "?" & argString & "page=" & pindex - 1 & "'>[上頁]</a>") else Response.Write("[首頁]") Response.Write(" ") Response.Write("[上頁]") end if Response.Write(" ") if pindex<pages then Response.Write("<a href='" & fileName & "?" & argString & "page=" & pindex + 1 & "'>[下頁]</a>") Response.Write(" ") Response.Write("<a href='" & fileName & "?" & argString & "page=" & pages & "'>[末頁]</a>") else Response.Write("[下頁]") Response.Write(" ") Response.Write("[末頁]") end if end if '// if showNumber then Response.Write(" ") for i = 4 to 1 step -1 if (pindex - i)>0 then Response.Write("<a href='" & fileName & "?" & argString & "page=" & pindex - i & "'>" & pindex - i & "</a>") Response.Write(" ") end if next '// Response.Write("<span style='color:red;'>" & pindex & "</span>") '// for i = 1 to 4 if (pindex + i)<=pages then Response.Write(" ") Response.Write("<a href='" & fileName & "?" & argString & "page=" & pindex + i & "'>" & pindex + i & "</a>") end if next '// end if '// end function %>