shawl.qiu asp 记录集分页类(vbscript 1.0 && jscript 1.1)
说明:这个没多大技术含量, 就不说明了...
目录:
1. vbscript
1.1 vbscript pagination 类
1.2 vbscript pagination 类使用参考
2. jscript
2.1 jscript pagination 类
2.2 jscript pagination 类使用参考
shawl.qiu
2007-01-22
http://blog.csdn.net/btbtd
内容:
1. vbscript
1.1 vbscript pagination 类
- '---------------------------------------------------------------------'
- ' shawl.qiu asp/vbscript 记录集分页类 v1.0
- '---------------------------------------------------------------------'
- '---------------------------------------------------------------------begin class pagination
- class pagination
- '------------------------------------begin event
- private sub class_initialize()
- auSubject="shawl.qiu asp/vbscript 记录集分页类"
- auVersion="v1.0"
- au="shawl.qiu"
- auEmail="shawl.qiu@gmail.com"
- auBlog="http://blog.csdn.net/btbtd"
- auCreateDate="2007-1-21"
- pagesize=10
- absltpage=1
- listnum=10
- queryid="page"
- wordFirst="首页"
- wordPreviousTen="上十"
- wordPrevious="上一"
- wordNext="下一"
- wordNextTen="下十"
- wordLast="末尾"
- cssCrCurLink="#FFCCFF"
- cssCrNoneLink="#ccc"
- cssJumpBox="border:0px;border-bottom:1px dashed black;"
- bGetRs=false
- iRecordCount=0
- debug=false
- end sub
- private sub class_terminate()
- end sub
- '------------------------------------end event
- '------------------------------------begin public variable
- '---------------begin about
- public auSubject, auVersion, au, auEmail, auBlog, auCreateDate
- '---------------end about
- public pagesize
- public absltpage
- public listnum
- public queryid
- public wordFirst
- public wordPreviousTen
- public wordPrevious
- public wordNext
- public wordNextTen
- public wordLast
- public cssCrCurLink
- public cssCrNoneLink
- public cssJumpBox
- public debug
- '------------------------------------end public variable
- '------------------------------------begin public method
- '------------------------------------end public method
- public property get list()
- suGetList()
- end property
- public property get info()
- suInfo()
- end property
- public property let rs(byref oRs)
- set rs_=oRs
- end property
- '------------------------------------begin private variable
- '------------------------------------end private variable
- private bGetRs
- private iRecordCount
- private rs_
- '------------------------------------begin private method
- private sub suGetList()
- if rs_.eof or rs_.bof then exit sub '记录集为空'
- if not isNumeric(absltpage) then absltpage=1
- absltpage=absltpage-0
- iRecordCount=rs_.RecordCount
- if iRecordCount<pagesize then exit sub '分页数大于记录总炸
- bGetRs=true
- dim iPgAll:iPgAll=int(iRecordCount/-pagesize)*-1
- if absltpage<1 then absltpage=1
- if absltpage>iPgAll then absltpage=iPgAll
- rs_.PageSize=pagesize
- rs_.AbsolutePage=absltpage
- dim iNumLink
- dim sUrl:sUrl="?"&Request.ServerVariables("query_string")&"&"&queryid&"="
- sUrl=fRe(sUrl, false, true, false, "/b"&queryid&"/=.*[^&]", queryid&"=")
- sUrl=fRe(sUrl, false, true, false, "/?/&", "?")
- sUrl=fRe(sUrl, false, true, false, "/&/&", "&")
- Response.write("<div class='sqPaged'>")
- if absltpage=1 then '-------------------首页'
- Response.write("<font style='color:"&cssCrNoneLink&"'>"&wordFirst&"</font> ")
- else
- Response.write("<a href='"&sUrl&"1'>"&wordFirst&"</a> ")
- end if
- if absltpage<=10 then '-------------------上十'
- Response.write("<font style='color:"&cssCrNoneLink&"'>"&wordPreviousTen&"</font> ")
- else
- Response.write("<a href='"&sUrl&(absltpage-(absltpage mod 10)-9)&"'>"&_
- wordPreviousTen&"</a> ")
- end if
- if absltpage<=1 then '-------------------上一'
- Response.write("<font style='color:"&cssCrNoneLink&"'>"&wordPrevious&"</font> ")
- else
- Response.write("<a href='"&sUrl&(absltpage-1)&"'>"&wordPrevious&"</a> ")
- end if
- for iNumLink=(absltpage-(absltpage mod 10)+1) to (absltpage-(absltpage mod 10)+10)
- if iNumLink>iPgAll then exit for
- if iNumLink=absltpage then
- Response.write("<font style='color: "&cssCrCurLink&";'>"&iNumLink&"</font> ")
- else
- Response.write("<a href='"&sUrl&iNumLink&"'>"&iNumLink&"</a> ")
- end if
- next
- if absltpage>=iPgAll then '-------------------下一'
- Response.write("<font style='color:"&cssCrNoneLink&"'>"&wordPrevious&"</font> ")
- else
- Response.write("<a href='"&sUrl&(absltpage+1)&"'>"&wordNext&"</a> ")
- end if
- if debug then
- Response.write("~~~下十:")
- Response.write(absltpage+10-(absltpage mod 10))
- Response.write("~~~~")
- Response.write(absltpage mod 10)
- Response.write("~~~~")
- Response.write((absltpage-(absltpage mod 10)+11))
- Response.write("~~~")
- end if
- if (absltpage-(absltpage mod 10)+11)>=iPgAll then '-------------------下十'
- Response.write("<font style='color:"&cssCrNoneLink&"'>"&wordNextTen&"</font> ")
- else
- Response.write("<a href='"&sUrl&(absltpage+10-(absltpage mod 10)+1)&"'>"&wordNextTen&"</a> ")
- end if
- if absltpage=iPgAll then '--------------------末尾'
- Response.write("<font style='color:"&cssCrNoneLink&"'>"&wordLast&"</font> ")
- else
- Response.write("<a href='"&sUrl&iPgAll&"'>"&wordLast&"</a> ")
- end if
- Response.write("转到:<input type='text' size='6' style='"&cssJumpBox&"'"&_
- " οnkeypress='fG2Url(this.value,event)' />")
- Response.write("<script type='text/javascript'>"&vbcrlf)
- Response.write("//<![CDATA["&vbcrlf)
- Response.write(" function fG2Url(sUrl, oEvt){"&vbcrlf)
- Response.write(" if(!oEvt)var oEvt=window.event;"&vbcrlf)
- Response.write(" var kc=oEvt.which||oEvt.keyCode;"&vbcrlf)
- Response.write(" if(kc==13){"&vbcrlf)
- Response.write(" window.location.href='?cat1id=1&page='+sUrl}"&vbcrlf)
- Response.write(" }"&vbcrlf)
- Response.write("//]]>"&vbcrlf)
- Response.write("</script>"&vbcrlf)
- Response.write("</div>")
- end sub 'suGetList shawl.qiu code'
- private sub suInfo()
- if rs_.Eof or rs_.Bof then exit sub
- dim iRc
- if bGetRs then
- iRc=iRecordCount
- else
- iRc=rs_.RecordCount
- end if
- if iRc<1 then exit sub
- Response.write("<div class='sqPgInfo'>")
- Response.write(rs_.PageSize&"篇/页 "&rs_.AbsolutePage&"/"&_
- (int(iRc/-rs_.PageSize)*-1)&"页 共"&iRc&"篇")
- Response.write("</div>")
- end sub 'suInfo shawl.qiu code'
- private function fRe(str,glb,igc,mtl,pt,rpt)
- dim re
- set re=new RegExp
- re.global=glb
- re.ignoreCase=igc
- re.multiline=mtl
- re.pattern=pt
- fRe=re.replace(str,rpt)
- set re=nothing
- end function 'fRe shawl.qiu code'
- '------------------------------------end private method
- end class
- '---------------------------------------------------------------------end class pagination
- shawl.qiu framework vbscript server-side
- ---/------------------------------------------------------------------------------
- class pagination
- ---/----------------------------------------------------
- dim conn
- conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data source="&_
- Server.MapPath("/data/shawlqiu.mdb")
- dim rs, oRs
- set rs=new data
- set oRs=rs.open("select title, articleid from shawlqiu_ order by articleid desc",_
- conn, 1, 1)
- dim paged
- dim iPage:iPage=Request.QueryString("page")
- if iPage="" then iPage=1
- set paged=new pagination
- paged.debug=false
- paged.rs=oRs
- paged.pagesize=20
- paged.absltpage=iPage
- paged.listnum=10
- paged.queryid="page"
- paged.list
- paged.info
- set paged=nothing
- rs.customList oRs, GetRef("fList")
- 'rs.list(oRs)
- rs.close(oRs)
- set rs=nothing
- dim iAtCount:iAtCount=0
- function fList(byref rs)
- iAtCount=iAtCount+1
- if iAtCount>20 then exit function
- Response.write("<br/><a href='?id="&rs("articleid")&"'>"&_
- rs("title")&"</a>")
- end function
2.1 jscript pagination 类
- <%
- /*-----------------------------------------------------------------------------------*/
- * shawl.qiu asp/jscript 记录集分页类 v1.1
- /*-----------------------------------------------------------------------------------*/
- //---------------------------------begin class pagination()-------------------------------//
- function pagination(){ // shawl.qiu code
- //------------------------------------begin public variable
- //---------------begin about
- this.auSubject='shawl.qiu asp/jscript 记录集分页类';
- this.auVersion='v1.1';
- this.au='shawl.qiu';
- this.auEmail='shawl.qiu@gmail.com';
- this.auBlog='http://blog.csdn.net/btbtd';
- this.auCreateDate='2007-1-10';
- this.auUpdate='2007-1-22';
- //---------------end about
- this.rs=''; // recordset object
- this.pagesize=20; // recordset.PageSize;
- this.absltpage=1; // recordset.AbsolutePage;
- this.listnum=10; // show the link list;
- this.queryid='page'; // url querystring('page');
- this.word=function(){};
- this.word.first='首页';
- this.word.last='尾页';
- this.word.previousTen='上十';
- this.word.previous='上一';
- this.word.next='下一';
- this.word.nextTen='下十';
- //------------------------------------end public variable
- //------------------------------------begin public method
- this.getlist=function(){
- tl_exec=true;
- tl_rscount=tl.rs.RecordCount;
- if(!tl_rscount)return false;
- if(tl_rscount=='')return false;
- if(tl_rscount===0)return false;
- var pgAll=Math.ceil(tl_rscount/tl.pagesize);
- if(tl.pagesize>tl_rscount)return false;
- var sUrl='?'+Request.ServerVariables("QUERY_STRING")+'&'+tl.queryid+'=';
- var re=new RegExp('//b'+tl.queryid+'/=.*[^&]','i')
- sUrl=sUrl.replace(re,tl.queryid+'=').replace('?&','?').replace('&&','&');
- tl.rs.PageSize=tl.pagesize; // 设置每页大小
- if(tl.absltpage<1) tl.absltpage=1; // 当前所在页
- if(tl.absltpage>pgAll) tl.absltpage=pgAll;
- tl.rs.AbsolutePage=tl.absltpage;
- Response.write('<div class="sqPagedList">');
- tl.absltpage>1?Response.Write('<a href="'+sUrl+'1">'+tl.word.first+'</a> ')
- :Response.Write('<span class="sqPagedNonLink">'+tl.word.first+'</span> ');
- if(pgAll>tl.listnum)
- tl.absltpage>10?Response.Write('<a href="'+sUrl+(tl.absltpage-0-10-(tl.absltpage%10)+1)+'">'+
- tl.word.previousTen+'</a> ') :Response.Write('<span class="sqPagedNonLink">'+
- tl.word.previousTen+'</span> ');
- tl.absltpage>1?Response.Write('<a href="'+sUrl+(tl.absltpage-1)+'">'+
- tl.word.previous+'</a> ')
- :Response.Write('<span class="sqPagedNonLink">'+tl.word.previous+'</span> ');
- for(var i=0, temp=tl.absltpage-(tl.absltpage%tl.listnum)+1, temp_=''; i<tl.listnum;
- temp++, i++){
- if(temp>pgAll) break;
- temp==tl.absltpage?Response.Write('<span class="sqPagedCurLink">'+temp+'</span> ')
- :Response.Write('<a href="'+sUrl+temp+'">'+temp+'</a> ');
- }
- tl.absltpage<pgAll?Response.Write('<a href="'+sUrl+(tl.absltpage-0+1)+'">'+
- tl.word.next+'</a> ')
- :Response.Write('<span class="sqPagedNonLink">'+tl.word.next+'</span> ');
- if(pgAll>tl.listnum)
- tl.absltpage<pgAll-9?Response.Write('<a href="'+sUrl+(tl.absltpage-0+
- 10-(tl.absltpage%10)+1)+'">'+ tl.word.nextTen+'</a> ')
- :Response.Write('<span class="sqPagedNonLink">'+tl.word.nextTen+'</span> ');
- tl.absltpage!=pgAll?Response.Write(' <a href="'+sUrl+pgAll+'">'+tl.word.last+'</a>')
- :Response.Write(' <span class="sqPagedNonLink">'+tl.word.last+'</span>');
- Response.write(' 转到:<input type="text" size="6" '+
- 'class="sqJump" onkeypress="fG2Url(this.value,event)" />/n' );
- Response.write('<script type="text/javascript">/n')
- Response.write('//<![CDATA[/n')
- Response.write(' function fG2Url(sUrl, oEvt){/n')
- Response.write(' if(!oEvt)var oEvt=window.event;/n')
- Response.write(' var kc=oEvt.which||oEvt.keyCode;/n')
- Response.write(' if(kc==13){/n')
- Response.write(' window.location.href="'+sUrl+'"+sUrl}/n')
- Response.write(' }')
- Response.write('/n//]]>')
- Response.write('</script>');
- Response.write('<style type="text/css">/n');
- Response.write('/* <![CDATA[ *//n');
- Response.write(' .sqJump{/n');
- Response.write(' border:0px;/n');
- Response.write(' border-bottom:1px dashed black;/n');
- Response.write(' }/n');
- Response.write('/* ]]> *//n');
- Response.write('</style>');
- Response.write('</div>');
- } // end this.getlist
- this.getinfo=function(){
- var rscount=0;
- if(!tl_exec){
- rscount=tl.rs.RecordCount;
- } else {
- rscount=tl_rscount;
- }
- Response.write('<div class="sqPagedInfo">');
- Response.Write(tl.rs.PageSize+'篇/页 ');
- Response.Write(tl.rs.AbsolutePage+'/'+tl.rs.PageCount+'页 ');
- Response.Write('共'+tl_rscount+'篇 ');
- Response.write('</div>');
- } // this.getinfo
- //------------------------------------end public method
- //------------------------------------begin private variable
- var tl=this;
- var tl_rscount=0;
- var tl_exec=false;
- //------------------------------------end private variable
- //------------------------------------begin private method
- //------------------------------------end private method
- } // shawl.qiu code
- //---------------------------------end class pagination()---------------------------------//
- %>
- shawl.qiu framework jscript server-side
- ---/------------------------------------------------------------------------------
- pagination()
- <%
- var conn= "Provider=Microsoft.Jet.OLEDB.4.0;persist security info=false;Data source="+
- Server.MapPath("sqEditor/data/shawlqiu.mdb");
- var rs=new ActiveXObject('adodb.recordset');
- rs.Open('select * from shawlqiu_', conn, 1)
- var page=Request.QueryString('page')>0? Request.QueryString('page'): 1;
- var paged=new pagination();
- paged.rs=rs;
- paged.pagesize=20;
- paged.absltpage=page;
- paged.listnum=10;
- paged.queryid='page';
- Response.write('<div class="pagenav">');
- paged.getlist();
- paged.getinfo();
- Response.write('</div>');
- paged=null;
- Response.write('<p/>');
- for(var i=0; i<20; i++){
- if(rs.Eof||rs.Bof) break;
- Response.Write((rs('title')+' ').link('?id=edit&atc='+rs('articleid')));
- Response.Write('<br/>');
- rs.MoveNext
- }
- rs.Close();
- rs=null;
- %>