程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> ASP技巧 >> 在ASP中,用JScript腳本實現分頁的另類辦法

在ASP中,用JScript腳本實現分頁的另類辦法

編輯:ASP技巧

<%@LANGUAGE="javaSCRipT" CODEPAGE="936"%>
<!--#include file="connect.ASP"-->
<!--#include file="news.ASP"-->
<%
var DataSet,sql,DataList;
var i=0;
var j=0;
DataList=new News();
DataSet=Server.CreateObject("Adodb.recordset");
sql="select * from News where ngroup='集團新聞' order by id desc";
DataSet.Open(sql,DataConn,1,1);

//是否有數據
if ((DataSet.eof)&&(DataSet.bof))
{
   Response.Write("<BR>" );
   Response.Write("=== 暫無 ===");
   Response.Write("<BR><BR>");
   Response.End();
}

//記錄總數
NumRecords=DataSet.RecordCount;

//設定每頁最大記錄數
PageSize=3;

//總頁數
NumPages=Math.ceil(NumRecords/PageSize);


//當前頁
i=Request.QueryString("CurrentPageID").Count;
if (i==0)
{
   CurrentPageID=1;
}
else
{
   CurrentPageID=parseInt(Request.QueryString("CurrentPageID"));
}

//初始化
PReviousPageID=CurrentPageID-1;
NextPageID=CurrentPageID+1;
HomePage=1;
EndPage=NumPages;

//內容列表
DataSet.MoveFirst;
DataSet.Move((CurrentPageID-1)*PageSize,1);
while (!DataSet.eof && j<PageSize)
{
    Response.Write("<a href=show.ASP?id="+DataSet("id")+" target=\"_blank\">"+DataSet("subject")+"</a><br>");
 j=j+1;
 DataSet.MoveNext;
}

//設定URL
if (CurrentPageID == HomePage)
{  
   Response.Write("<p class='Normal'><a href=list.ASP?CurrentPageID="+HomePage+">首頁</a>&nbsp;&nbsp;");
   Response.Write("上一頁&nbsp;&nbsp;");
   Response.Write("<a href=list.ASP?CurrentPageID="+NextPageID+">下一頁</a>&nbsp;&nbsp;");
   Response.Write("<a href=list.ASP?CurrentPageID="+EndPage+">尾頁</a>&nbsp;&nbsp;</p>");
}
else if (CurrentPageID == EndPage)
    {
        Response.Write("<p class='Normal'><a href=list.ASP?CurrentPageID="+HomePage+">首頁</a>&nbsp;&nbsp;");
        Response.Write("<a href=list.ASP?CurrentPageID="+PreviousPageID+">上一頁</a>&nbsp;&nbsp;");
        Response.Write("下一頁&nbsp;&nbsp;");
        Response.Write("<a href=list.ASP?CurrentPageID="+EndPage+">尾頁</a>&nbsp;&nbsp;</p>");
    }
 else
 {
        Response.Write("<p class='Normal'><a href=list.ASP?CurrentPageID="+HomePage+">首頁</a>&nbsp;&nbsp;");
        Response.Write("<a href=list.ASP?CurrentPageID="+PreviousPageID+">上一頁</a>&nbsp;&nbsp;");
        Response.Write("<a href=list.ASP?CurrentPageID="+NextPageID+">下一頁</a>&nbsp;&nbsp;");
        Response.Write("<a href=list.ASP?CurrentPageID="+EndPage+">尾頁</a>&nbsp;&nbsp;</p>");
 }
%>

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved