在ASP中,用JScript指令碼實現分頁的另類辦法。

來源:互聯網
上載者:User
<%@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;");

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.