Asp分页Function



'///****************************分页的function*****************************************'//参数说明'//Sql:查询所需的Sql语句'//PageSize:每页显示的记录个数'//Colspan:表格的列数'//bgcolor:显示翻页的背景色'//Str:Y是为后台显示,其他为前台显示'//Country:C时为显示中文翻页,其他显示英文翻页'////************************************************************************************Public SUB Show_Page_Html(Sql,PageSize,Colspan,bgcolor,Str,Country)'分页   Dim MaxPerPage,Rs,gstBookiD,totalPut,CurrentPage,TotalPages,i,j   IF NOT Isempty(Request("Page")) THEN  '这个page是后面的select里面的      CurrentPage=Cint(Request("Page")) '这里一定要转换成int否则不行!!   ELSE      CurrentPage=1   END IFSet Rs=Server.CreateObject("Adodb.RecordSet")Rs.Open Sql,Conn,1,1,1I=1IF Rs.RecordCount=0 THEN WITH P.E("<tr>").E("<td colspan="&Colspan&"><center><font color=Red><B>没有记录</B></font></center></td>").E("</tr>")END WITHIF Str="Y" THENRESPONSE.ENDEND IF ELSE     Rs.PageSize=PageSize   TotalPut=Rs.RecordCount '记录总数     TotalPage=Rs.PageCount     MaxPerPage=Rs.PageSize              IF CurrentPage>TotalPage THEN            CurrentPage=TotalPage        END IF     IF CurrentPage=1 THEN       Call ShowContent(Rs,TotalPut,MaxPerPage)'显示读取的记录      Call Show_Page_Js(TotalPut,MaxPerPage,5,Colspan,bgcolor,Country)'JS显示翻页       ELSE           IF (CurrentPage-1)*MaxPerPage<totalPut THEN           Rs.move(CurrentPage-1)*MaxPerPage           Dim BookMark           BookMark=Rs.BookMark '移动到开始显示的记录位置         Call ShowContent(Rs,TotalPut,MaxPerPage)'显示读取的记录         Call Show_Page_Js(TotalPut,MaxPerPage,5,Colspan,bgcolor,Country)'JS显示翻页       END IF     END IF        Rs.Close  END IF  SET Rs=Nothing    'Conn.Close  'SET Conn=NothingEND SUB

'**********************************************************'翻页的function '**********************************************************Public SUB Show_Page_Js(TotalPut,PageSize,L_R,Colspan,bgcolor,Country)'JS显示翻页

Response.Write("<tr bgcolor='#"&bgcolor&"' class='unnamed1'>")Response.Write("<td colspan='"&Colspan&"' class='unnamed1'> <div align='center' class='unnamed1'>")IF Request.QueryString("Page")="" THENPageNow=1ELSEPageNow=Request.QueryString("Page")END IFResponse.Write(""&Chr(60)&"Script Language=JavaScript"&Chr(62)&"")IF Country="C" THENResponse.Write("ShowoPage("&Chr(34)&""&Chr(34)&","&Chr(34)&""&Chr(34)&","&Chr(34)&"页次<font color='black'><B>:"&Chr(34)&","&Chr(34)&"</B></font> / "&Chr(34)&","&Chr(34)&"<font color='black'><B>"&Chr(34)&","&Chr(34)&"</B></font> "&Chr(34)&","&Chr(34)&"本页记录:<font color='black'><B>"&Chr(34)&","&Chr(34)&"</B></font>&nbsp;"&Chr(34)&","&Chr(34)&"&nbsp;总记录<font color='black'><B>:"&Chr(34)&","&Chr(34)&"</B></font>&nbsp;&nbsp;"&Chr(34)&","&Chr(34)&"<font face=webdings>9</font>"&Chr(34)&","&Chr(34)&"<font face=webdings>7</font>"&Chr(34)&","&Chr(34)&"<font face=webdings>8</font>"&Chr(34)&","&Chr(34)&"<font face=webdings>:</font>"&Chr(34)&","&Chr(34)&"&nbsp;&nbsp;跳转:"&Chr(34)&","&Chr(34)&"<font color='black'><B>"&Chr(34)&","&Chr(34)&"</B></font>"&Chr(34)&","&Chr(34)&"<font color='red'><B>"&Chr(34)&","&Chr(34)&"</B></font>"&Chr(34)&","&Chr(34)&""&Chr(34)&","&Chr(34)&""&Chr(34)&","&Chr(34)&""&Chr(34)&","&Chr(34)&""&Chr(34)&","&TotalPut&","&PageSize&","&L_R&","&PageNow&")")ELSEResponse.Write("ShowoPage("&Chr(34)&""&Chr(34)&","&Chr(34)&""&Chr(34)&","&Chr(34)&"Page/PageCount<font color='black'><B>:"&Chr(34)&","&Chr(34)&"</B></font> / "&Chr(34)&","&Chr(34)&"<font color='black'><B>"&Chr(34)&","&Chr(34)&"</B></font> "&Chr(34)&","&Chr(34)&"Records:<font color='black'><B>"&Chr(34)&","&Chr(34)&"</B></font>&nbsp;"&Chr(34)&","&Chr(34)&"&nbsp;RecordCount<font color='black'><B>:"&Chr(34)&","&Chr(34)&"</B></font>&nbsp;&nbsp;"&Chr(34)&","&Chr(34)&"<font face=webdings>9</font>"&Chr(34)&","&Chr(34)&"<font face=webdings>7</font>"&Chr(34)&","&Chr(34)&"<font face=webdings>8</font>"&Chr(34)&","&Chr(34)&"<font face=webdings>:</font>"&Chr(34)&","&Chr(34)&"&nbsp;&nbsp;Go:"&Chr(34)&","&Chr(34)&"<font color='black'><B>"&Chr(34)&","&Chr(34)&"</B></font>"&Chr(34)&","&Chr(34)&"<font color='red'><B>"&Chr(34)&","&Chr(34)&"</B></font>"&Chr(34)&","&Chr(34)&""&Chr(34)&","&Chr(34)&""&Chr(34)&","&Chr(34)&""&Chr(34)&","&Chr(34)&""&Chr(34)&","&TotalPut&","&PageSize&","&L_R&","&PageNow&")")END IFResponse.Write(""&Chr(60)&""&Chr(47)&"Script"&Chr(62)&"")Response.Write("</div></td>")Response.Write("</tr>")END SUB

 

/***************************分页的js***************************/

var url,re,CurrentPage,FirstPageUrl,PrevPageUrl,NextPageUrl,LastPageUrl,CurrPage,PageCount,prevpage,nextpage,PageStart,PageEnd,i,ipage;   url=""+document.location;   if (url.indexOf("Page=")==-1)    {     CurrPage=1;    }    else    {      re=/(/S.*)(Page=/d*)(/S.*|/S*)/g;         CurrentPage=url.replace(re,"$2");       url=url.replace("&"+CurrentPage,"");       url=url.replace(CurrentPage+"&","");       url=url.replace(CurrentPage,"");            CurrentPage=CurrentPage.replace("Page=","")      //var re=/(?:/S{1,}Page=|/D.*)/g;         //var CurrentPage=url.replace(re,"");        //url=url.replace("&page="+CurrentPage,"");      //url=url.replace("page="+CurrentPage+"&","");       //url=url.replace("page="+CurrentPage,"");        CurrPage=CheckNum(CurrentPage,1)     }         if (url.indexOf("?")==-1)    {     url=url+"?";     }     else     {     url=url+"&";    }   url=url.replace("?&","?");     url=url.replace("&&","&");      function isInt(value){ var i=parseInt(value,10);  if(!isNaN(value)) {  if(i==value){   return 1;  //是一个整数  }else{   return 2;  //是一个浮点数  } }else{  return 0;   //不是数字 } }function CheckNums(iform){if(isInt(iform.page.value)!=1){alert('页码必须为整数!');iform.btnGo.disabled=true;return false;} else{iform.btnGo.disabled=false;}}

function GoUrl(iform){  url=url+'&Page='   url=url.replace("?&","?");  url=url.replace("&&","&");  ipage=iform.page.value;  lurl=url+ipage;window.location=""+lurl+"";}

function isNumberString (InString,RefString){if(InString.length==0) return (false);for (Count=0; Count < InString.length; Count++)  {TempChar= InString.substring (Count, Count+1);if (RefString.indexOf (TempChar, 0)==-1)return (false);}return (true);}function CheckNum(str,num){  str=""+str;     if (str.length>=1)       {       mynum=parseInt(str);       if (isNaN(mynum))         {         mynum=num;         }       }      else      {    mynum=num;      }     return (mynum);}

function CheckPage()  {  url=url+'&Page='   url=url.replace("?&","?");  url=url.replace("&&","&");  ipage=document.iform.page.value;  ipage=CheckNum(ipage,1)  if (ipage>=PageCount)  {    ipage=PageCount;  }  else if (ipage<=1)  {    ipage=1;  }  else  {       ipage=ipage;  }     document.iform.action=url+ipage;     document.iform.submit();}     function ShowoPage(Tabstart,Tabend,CurrPageFont1,CurrPageFont2,PageCountFont1,PageCountFont2,PrePageFont1,PrePageFont2,RecCountFont1,RecCountFont2,FirstFont,PrevFont,NextFont,LastFont,Jump,PageNumFont1,PageNumFont2,PageNumFont3,PageNumFont4,LinkFont1,LinkFont2,LinkFont3,LinkFont4,RecCount,RecPerPage,PageNum,pageInt)    {    if (RecCount%RecPerPage==0)     {        PageCount=RecCount/RecPerPage;     }   else     {       PageCount=(parseInt(RecCount/RecPerPage)+1);    }   prevpage=parseInt(CurrPage-1);    if (prevpage<1)    {     prevpage=1;    }    nextpage=parseInt(CurrPage+1)    if (nextpage>PageCount)    {     nextpage=PageCount;    } if  (CurrPage==1&&PageCount==1)     {       CurrPage=1;    FirstPageUrl="<font color=#999999>"+LinkFont3+FirstFont+LinkFont4+"</font>";    PrevPageUrl="<font color=#999999>"+LinkFont3+PrevFont+LinkFont4+"</font>";    NextPageUrl="<font color=#999999>"+LinkFont3+NextFont+LinkFont4+"</font>";       LastPageUrl="<font color=#999999>"+LinkFont3+LastFont+LinkFont4+"</font>";     }   else if (CurrPage<=1)     {       CurrPage=1;    FirstPageUrl="<font color=#999999>"+LinkFont3+FirstFont+LinkFont4+"</font>";    PrevPageUrl="<font color=#999999>"+LinkFont3+PrevFont+LinkFont4+"</font>";    NextPageUrl="<A href=/""+url+"Page="+nextpage+"/">"+LinkFont1+NextFont+LinkFont2+"</A>";       LastPageUrl="<A href=/""+url+"Page="+PageCount+"/">"+LinkFont1+LastFont+LinkFont2+"</A>";     }   else if (CurrPage>=PageCount)     {       CurrPage=PageCount;    FirstPageUrl="<A href=/""+url+"Page=1/">"+LinkFont1+FirstFont+LinkFont2+"</A>";    PrevPageUrl="<A href=/""+url+"Page="+prevpage+"/">"+LinkFont1+PrevFont+LinkFont2+"</A>";    NextPageUrl="<font color=#999999>"+LinkFont3+NextFont+LinkFont4+"</font>";       LastPageUrl="<font color=#999999>"+LinkFont3+LastFont+LinkFont4+"</font>";     }      else     {       CurrPage=CurrPage;        FirstPageUrl="<A href=/""+url+"Page=1/">"+LinkFont1+FirstFont+LinkFont2+"</A>";    PrevPageUrl="<A href=/""+url+"Page="+prevpage+"/">"+LinkFont1+PrevFont+LinkFont2+"</A>";       NextPageUrl="<A href=/""+url+"Page="+nextpage+"/">"+LinkFont1+NextFont+LinkFont2+"</A>";       LastPageUrl="<A href=/""+url+"Page="+PageCount+"/">"+LinkFont1+LastFont+LinkFont2+"</A>";  }  if (CurrPage-PageNum<=1)     {       PageStart=1;     }   else     {       PageStart=CurrPage-PageNum;   }  if (CurrPage+PageNum>=PageCount)     {       PageEnd=PageCount;     }    else     {      PageEnd=CurrPage+PageNum;  }  if(pageInt>=PageCount)  {  RecPerPage=RecCount-RecPerPage*(PageCount-1);  }  document.write (""+Tabstart);  document.write (CurrPageFont1+CurrPage+CurrPageFont2+PageCountFont1+PageCount+PageCountFont2+PrePageFont1);  document.write (RecPerPage+PrePageFont2+RecCountFont1+RecCount+RecCountFont2+FirstPageUrl+PrevPageUrl);  for (i=PageStart;i<=PageEnd;i++)  {   if (i==CurrPage)     {     document.write ("&nbsp;"+PageNumFont3+i+PageNumFont4+"&nbsp;");     }    else     {  document.write ("&nbsp;<A href=/""+url+"Page="+i+"/">"+PageNumFont1+i+PageNumFont2+"</A>&nbsp;");  }   }  document.write (NextPageUrl+LastPageUrl+Jump);  document.write ("<INPUT type=/"text/"  name=/"page/" size=/"2/"  onblur=/"CheckNums(this.form)/"  onmaxlength=/"7/" style=/"border: 1px solid #000000;font-size: 12px;color: #000000;width:40px;height: 18px;/" id=/"page/" value=/""+pageInt+"/"> <INPUT type=/"button/"  Onclick=/"GoUrl(this.form)/" style=/"border: 1px solid #000000;font-size: 12px;color: #000000;height: 18px;/" value=/"Go/"  disabled name=/"btnGo/">"+Tabend+"");  }

 

/****************************调用的例子******************************/

<%       StrSQL = "SELECT * FROM depot ORDER BY enterdate DESC"  Call Show_Page_Html(StrSQL,16,10,"f4f4f4","Y","C")  SUB ShowContent(Rs,TotalPut,MaxPerPage)     Dim i     Dim k     k=(TotalPut-MaxPerPage*(CurrentPage-1))+1     i=0

%>

<table width="100%" border="0" cellpadding="0" cellspacing="0">  <tr bgcolor="#666666">     <td width="60%" height="16"><strong><font color="#FFFFFF">===出入库管理===</font></strong></td>    <td width="40%" align="right"> <table width="41%" border="0" cellpadding="0" cellspacing="0">        <tr>           <td bgcolor="#339FF0"> <div align="center"><a href="input_room.asp"><font color="#FFFFFF" size="3">货物入库开单&gt;&gt;</font></a></div></td>        </tr>      </table></td>  </tr>  <tr>     <td colspan="2"><table width="100%" border="0" cellpadding="2" cellspacing="1" bordercolor="#CCCCCC" class=table>        <tr bgcolor="#FFFFFF">           <td width="19%" height="22"> <div align="center"><strong><font size="2">入库时间</font></strong></div></td>          <td width="37%"> <div align="center"><strong><font size="2">入库单位</font></strong></div></td>          <td width="21%"> <div align="center"><strong><font size="2">货物名称</font></strong></div></td>          <td width="12%"> <div align="center"><strong><font size="2">货物状态</font></strong></div></td>          <td width="11%"> <div align="center"><strong><font size="2">出入库操作</font></strong></div></td>        </tr>        <%      DO WHILE NOT (Rs.EOF OR ERR OR Rs.BOF)       k=k-1      if(i mod 2=0) then     classtype = "tr1"    else     classtype = "tr2"    end if%>        <tr bgcolor="#F0EFD0">           <td><font size="2">             <% = rs("enterdate") %>            </font></td>          <td><font size="2"> <a href="input_item.asp?id=<%=rs("id")%>">            <% = rs("enterunit") %>            </a> </font></td>          <td><font size="2">             <% = rs("proname") %>            </font></td>          <td><div align="center"><font size="2">               <%    IF rs("enterdate") <> "" THEN    Response.Write("货已入库")   ELSEIF(rs("enterdate") <> "" AND rs("outdate") <> "") THEN    Response.Write("货已出库")   END IF   %>              </font></div></td>          <td valign="bottom">             <div align="center"><font size="2">   <% if (rs("enterdate")<> "" AND rs("outdate") <> "") then %>   <font color="#FF0000" size="2">货已出库</font>   <% else%>              <a href="out_room.asp?id=<%=rs("id")%>"><img src="images/out_room.jpg" width="72" height="17" border="0"></a>               <%end if%>              </font></div></td>        </tr>        <%   I=I+1     IF I>=MaxPerPage THEN EXIT DO '循环时如果到尾部则先退出,如果记录达到页最大显示数,也退出        Rs.MoveNext   Loop       END SUB     %>

阅读更多
换一批

没有更多推荐了,返回首页