完美的ASP分页脚本

在2009-2010年写过简单个两个分页(调取页码的函数):

PHP分页(页码)函数(http://www.miaoqiyuan.cn/p/php-yema-fenye)
分享两个ASP分页(页码)函数(http://www.miaoqiyuan.cn/p/asp-yema-fenye)。

现在看有点乱了,最近有重新整理了下代码,重写了ASP的分页代码,生成的分页代码兼容BootStrap。代码如下:

 	'PageinationRecordSet  如果返回false,说明 Adodb.RecrodSet集 为空
 	'RecordSet  Adodb.RecrodSet集
 	'PageId  当前所在页
 	'PageSize  每页显示多少条?
 	'*PageCount 返回页码总数
 	function PageinationRecordSet(byref RecordSet,byref PageId,byval PageSize,byref PageCount)
 		if RecordSet.eof then
 			PageinationRecordSet = false
 		else
	 		RecordSet.PageSize = PageSize
	 		PageCount = RecordSet.PageCount
	 		if PageId > PageCount then PageId = PageCount
	 		RecordSet.absolutePage = PageId
	 		PageinationRecordSet = true
 		end if
 	end function
 	
 	'PageId  当前所在页
 	'PageCount  页码总数
 	'urlTemplate  链接模板
	function PageinationPageList(byval PageId,byval PageCount,byval urlTemplate)
		dim codeTemp,iPage
		
		if PageCount > 0 then
			codeTemp = "<ul class=""pagination"">"
			
			if PageId <= 1 then codeTemp = codeTemp & "<li class=""disabled"">" else codeTemp = codeTemp & "<li>"
			codeTemp = codeTemp & "<a href=""" & replace(urlTemplate,"{pg}",1) & """> 首页 </a></li>"
			if PageId <= 1 then codeTemp = codeTemp & "<li class=""disabled"">" else codeTemp = codeTemp & "<li>"
			codeTemp = codeTemp & "<a href=""" & replace(urlTemplate,"{pg}",PageId-1) & """>上一页</a></li>"
			
			for iPage = PageId - 5 to PageId + 5
				if iPage = PageId then
					codeTemp = codeTemp & "<li class=""active""><a href=""" & replace(urlTemplate,"{pg}",iPage) & """>" & iPage & "</a></li>"
				elseif iPage < PageId and iPage > 0 then
					codeTemp = codeTemp & "<li><a href=""" & replace(urlTemplate,"{pg}",iPage) & """>" & iPage & "</a></li>"
				elseif iPage > PageId and iPage <= PageCount then
					codeTemp = codeTemp & "<li><a href=""" & replace(urlTemplate,"{pg}",iPage) & """>" & iPage & "</a></li>"
				end if
			next
			
			if PageId >= PageCount then codeTemp = codeTemp & "<li class=""disabled"">" else codeTemp = codeTemp & "<li>"
			codeTemp = codeTemp & "<a href=""" & replace(urlTemplate,"{pg}",PageId + 1) & """>下一页</a></li>"
			if PageId >= PageCount then codeTemp = codeTemp & "<li class=""disabled"">" else codeTemp = codeTemp & "<li>"
			codeTemp = codeTemp & "<a href=""" & replace(urlTemplate,"{pg}",PageCount) & """>尾页</a></li>"
			
			PageinationPageList = codeTemp & "</ul>"
		end if
	end function

测试代码:


	pgId = Request.QueryString("pageid")	'当前页码
	pgSize = 10	'每页大小
	rsId = 0
	Rs.Open Query,Conn,1,1
	if PageinationRecordSet(Rs, pgId, pgSize, pgCount) then
		do while not Rs.Eof and rsId < pgSize
			rsId = rsId + 1
			
			'列表内容
			
			Rs.MoveNext
		loop
	end if
	Rs.Close

	'共 pgCount 页
	response.write PageinationPageList(pgId, pgCount, "./list.asp?pageid={pg}")  '输出分页代码

完美的ASP分页脚本》上有1条评论

  1. Pingback引用通告: angular.js 分页代码 | 苗启源

发表评论

电子邮件地址不会被公开。 必填项已用*标注