帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
分页显示的例子(显示记录背景色替换变化)
作者: 发布时间:2005-03-12 来源:
Code Title: Paging (modifiable)
Description: Add paging to your record retrieval. But, do it with the good'ol form field that allows you
to just type in directly what page ya wanna go to. This one is our fave! It even alternates the background
color (bgcolor) of each row, to make viewing the recordset even easier.. We use different tweaked versions
of this one all over our site! See an example of this code snippet on our International page.

We have made it so that it will display a hyperlinked first item in one column, then a truncated
description using the Left() function in the next column. The hyperlink will take you to the specific
article or record, (whatever you're using it for).

We use a javascript valid number checker on this one, just to make sure the person doesn't enter any weird
characters into the page number field of the form. We don't normally do this, but if ya want the
javascript for number checking, check out our jsNumberValidator.
Copy and paste this snippet as-is into your editor:


<%
Const adUseClient = 3
Const adOpenStatic = 3
specific = Request.QueryString("specific")
If specific = "" Then
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.CursorLocation = adUseClient
rs.CacheSize = 5
mypage = Request.Form("pgNum")
If mypage = "" Then mypage = 1
rs.Open "SELECT * FROM TABLE ORDER BY FIELD ASC", cnDZ, adOpenStatic
If Not rs.EOF Then
rs.MoveFirst
rs.PageSize = 20 'change this number to exactly how many records per page ya wanna show
maxcount = cint(rs.PageCount)
rs.AbsolutePage = mypage
howmanyrecs = 0
Response.Write"<table border=0>"
LinkCount = 0
While Not rs.EOF And howmanyrecs < rs.pagesize
If LinkCount Mod 2 = 0 Then bgColor = " bgcolor=#F0F0F0" Else bgColor = ""
Response.Write"<tr"&bgColor&"><td nowrap>"&_
"<a href=""myPage.asp?specific="&rs("ID")&""">"&rs("FIELD")&"</a></td>"&_
"<td width=""100%"" nowrap>"&Left(rs("FIELD2"),40)&"</td></tr>"
LinkCount = LinkCount + 1
rs.MoveNext
howmanyrecs = howmanyrecs + 1
Wend
Response.Write"</table>"
If maxcount > 1 Then
If mypage + 1 > maxcount Then nextPg = 1 Else nextPg = mypage + 1
Response.Write"<form method=post action=""myPage.asp"">"&_
"<nobr>Page "&mypage&" of "&maxcount&"      Navigate to Page:<input
type=text name=pgNum size=3 maxlength=3 value="""&nextPg&""">  <input type=submit name=gopgNum
value=GO></nobr></form>"
End If
Else Response.Write"Sorry, nothing is available at the moment."
End If
rs.Close
Set rs = Nothing
Else
Set rs = cnDZ.Execute("SELECT * FROM TABLE WHERE ID = "&specific&"")
Do Until rs.EOF
Response.Write""&rs("FIELD")&"<br>"&_
""&rs("FIELD2")&"<br>"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End If
%>


  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·在ASP中改善动态分页的性能  (2005-03-12)
 ·仅用xsl和asp实现分页功能  (2005-03-12)
 ·关于存储过程分页  (2005-03-12)
 ·一种理论上最快的Web数据库分页方  (2005-03-12)
 ·关于分页办法  (2005-03-12)
 ·在客户端执行数据库记录的分页显  (2005-03-12)
 ·在客户端执行数据库记录的分页显  (2005-03-12)
 ·在客户端执行数据库记录的分页显  (2005-03-12)
 ·1栏分页显示(附显示的形式前页,  (2005-03-12)
 ·1栏分页显示(附显示的形式[1][2  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统