蛙蛙推荐:分栏显示记录集的表格演示,并实现了分页
2004-11-05 11:05
513 查看
<!-- 本示例演示一个通用的记录集分栏显示,因为有的时候显示产品等要每行显示若干个,而不是每行显示一个。如有有这种分栏显示的表格,直接把下面的代码套进去就行了,本示例是每行显示2个记录,再最下面还显示了分页栏。 -->
<%
'打开数据库
Set conn = Server.CreateObject("ADODB.Connection")
strconn="Driver={sql server};server=localhost;database=northwind;uid=sa;pwd=sa;"
conn.Open strconn
'获取本页地址
Dim fileName,postion
fileName = Request.ServerVariables("script_name")
postion = InstrRev(fileName,"/")+1
fileName = Mid(fileName,postion)
'打开记录集
set rs=server.CreateObject("adodb.recordset")
rs.open "select titleofcourtesy,firstname,photopath from Employees order by employeeid desc",conn,1,1
%>
<!-- 产品展示表格 -->
<table width="90%" height="300" border="0" align="center">
<%
if not(rs.bof and rs.eof) then
pages=4
rs.pagesize=pages
if not isempty(Request.QueryString("page")) then
thispage=clng(Request.QueryString("page"))
else
thispage=1
end if
rscount=rs.recordcount
if thispage="" then thispage=1
if thispage<1 then thispage=1
if (thispage-1)*pages>rscount then
if (rscount mod pages)=0 then
thispage=rscount/pages
else
thispage=rscount/pages+1
end if
end if
if(rscount mod pages)=0 then
allpages=rscount/pages
else
allpages=rscount/pages+1
end if
rs.absolutepage=thispage
i=1
%>
<tr>
<%do while not rs.eof and pages>0 %>
<td valign="top"><a href="<%=rs("PhotoPath")%>" target="_blank"><img src="<%=rs("PhotoPath")%>" alt="" width="100" height="100" border="0"></a><br>
<%=rs("titleofcourtesy")&rs("firstname")%> </td>
<%
'分栏主要由下面这个判断来执行的,本例是每行显示两栏
if (i mod 2) =0 then
%>
</tr><tr>
<%end if%>
<%
pages = pages - 1
rs.movenext
i=i+1
loop
end if
%>
</table>
<!-- /产品展示表格 -->
<!-- 产品分页表格 -->
<table width="90%" border="0" align="center">
<tr>
<td> <center>
共<%=allpages%>页 当前第<%= thispage %>页
<% if thispage<>1 then %>
<a href="<%=filename&"?page=1"%>">首页</a> <a href="<%=filename&"?page="&(thispage-1)%>">上页</a>
<% End If %>
<% if thispage<>allpages then %>
<a href="<%=filename&"?page="&(thispage+1)%>">下页</a> <a href="<%=filename&"?page="&allpages&""%>">末页</a>
<% End If %>
</center></td>
</tr>
</table>
<!-- /产品分页表格 -->
<%
'打开数据库
Set conn = Server.CreateObject("ADODB.Connection")
strconn="Driver={sql server};server=localhost;database=northwind;uid=sa;pwd=sa;"
conn.Open strconn
'获取本页地址
Dim fileName,postion
fileName = Request.ServerVariables("script_name")
postion = InstrRev(fileName,"/")+1
fileName = Mid(fileName,postion)
'打开记录集
set rs=server.CreateObject("adodb.recordset")
rs.open "select titleofcourtesy,firstname,photopath from Employees order by employeeid desc",conn,1,1
%>
<!-- 产品展示表格 -->
<table width="90%" height="300" border="0" align="center">
<%
if not(rs.bof and rs.eof) then
pages=4
rs.pagesize=pages
if not isempty(Request.QueryString("page")) then
thispage=clng(Request.QueryString("page"))
else
thispage=1
end if
rscount=rs.recordcount
if thispage="" then thispage=1
if thispage<1 then thispage=1
if (thispage-1)*pages>rscount then
if (rscount mod pages)=0 then
thispage=rscount/pages
else
thispage=rscount/pages+1
end if
end if
if(rscount mod pages)=0 then
allpages=rscount/pages
else
allpages=rscount/pages+1
end if
rs.absolutepage=thispage
i=1
%>
<tr>
<%do while not rs.eof and pages>0 %>
<td valign="top"><a href="<%=rs("PhotoPath")%>" target="_blank"><img src="<%=rs("PhotoPath")%>" alt="" width="100" height="100" border="0"></a><br>
<%=rs("titleofcourtesy")&rs("firstname")%> </td>
<%
'分栏主要由下面这个判断来执行的,本例是每行显示两栏
if (i mod 2) =0 then
%>
</tr><tr>
<%end if%>
<%
pages = pages - 1
rs.movenext
i=i+1
loop
end if
%>
</table>
<!-- /产品展示表格 -->
<!-- 产品分页表格 -->
<table width="90%" border="0" align="center">
<tr>
<td> <center>
共<%=allpages%>页 当前第<%= thispage %>页
<% if thispage<>1 then %>
<a href="<%=filename&"?page=1"%>">首页</a> <a href="<%=filename&"?page="&(thispage-1)%>">上页</a>
<% End If %>
<% if thispage<>allpages then %>
<a href="<%=filename&"?page="&(thispage+1)%>">下页</a> <a href="<%=filename&"?page="&allpages&""%>">末页</a>
<% End If %>
</center></td>
</tr>
</table>
<!-- /产品分页表格 -->
相关文章推荐
- jsp+oracle实现数据库内容以表格形式在前台显示(包含分页)
- 记录集分页显示的实现
- 在ASP中轻松实现记录集分页显示
- 在ASP中轻松实现记录集分页显示
- 记录集分页显示策略五种实现方法
- 记录集分页显示策略五种实现方法
- 在ASP中轻松实现记录集分页显示
- 记录集分页显示策略五种实现方法
- Flex实现分页显示功能(mx:DataGrid) 推荐
- 巧用CSS实现表格的隐藏显示控制,类似分页效果
- List集合切割实现对已有数据的分页显示(LIST容器数据量不大的情况下推荐使用)
- (24)ExtJS之表格加载远程数据及其分页显示
- 自己实现的数据表格控件(dataTable),支持自定义样式和标题数据、ajax等各种自定义设置以及分页自定义
- BootStrap Table实现server分页序号连续显示功能(当前页从上一页的结束序号开始)
- JSP实现添加功能和分页显示实例分析
- JSP实现的简单分页显示效果代码
- 前端实现一个简单的表格分页
- 《实现JSP分页显示数据库》的阅读笔记
- jquery表格datagrid单元格显示图片及分页使用
- jsp servlet javaBean实现oracle数据库分页显示