当前位置: 首页 > 图文教程 > 网络编程 > ASP > 我用ASP写的m行n列的函数,动态输出创建TABLE行列

ASP
asp数个使用技巧
存储过程里的递归 实现方法
非常不错的列出sql服务器上所有数据库的asp代码
防范ASP木马的十大基本原则强列建议看下
雷客图ASP站长安全助手的ASP木马查找功能
防止别人盗链的好方法推荐
图片的入库与读取的方法
用asp实现无组件生成验证码的方法2种
用asp实现检测文件编码
[asp]怎么添加验证码的解决方法
ASP文章系统解决方案实现上一页下一页
ASP编程入门进阶(三):接触脚本程序
ASP编程入门进阶(四):内置对象Request
ASP编程入门进阶(五):内置对象Response
ASP编程入门进阶(六):Cookies讲座
ASP编程入门进阶(八):内置对象Session
ASP编程入门进阶(九):内置对象Application
ASP编码优化技巧8则
ASP编程入门进阶(十):Global.asa文件
ASP编程入门进阶(十一):Chat聊天程序

我用ASP写的m行n列的函数,动态输出创建TABLE行列


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 32 ::
收藏到网摘: n/a

没有用正常的循环tr内循环td的方法,所以就没有计算最后一页的记录集数量。
但当记录集不足时也同样能够自动补空行空列,如有不足请指出,谢谢。
使用方法很简单:
复制代码 代码如下:

<%
showData("查询语名")
Call pagehead(行数,列数)
'-------------------------------------------------------------------------------
'可以把下面的Response.Write()写到函数里面,看个人的爱好了。
Response.Write(FormatCRtable(表格宽度,表格高度))
Response.Write(PageFoot())
Call closeData()
%>

函数如下:

复制代码 代码如下:

<%
'-------------------------------------------------------------------------------
'Copyright 2005 by Jorkin.All Rights Reserved
'-------------------------------------------------------------------------------
Public rs
Public pageno,Cols,Rows,maxpageno,maxredcount,maxpagesize
'-------------------------------------------------------------------------------
Public Function showData(sqlstrings)
  Set rs=Server.CreateObject("ADODB.Recordset")
  rs.open sqlstrings,oconn,1,3
End Function
Public Function closeData()
  rs.close
  Set rs=Nothing
End Function
'初始化分页
'MaxRows =最大行数
'MaxCols =最大列数
'-------------------------------------------------------------------------------
Public Function PageHead(MaxRows,MaxCols)
'-------------------------------------------------------------------------------
  Rows=MaxRows
  Cols=MaxCols
  maxpagesize=1
  maxredcount=0
  maxpageno=0
  pageno=0
'-------------------------------------------------------------------------------
  maxredcount = rs.recordcount
  If maxredcount>0 then
  maxpagesize = Rows*Cols
  maxpageno = Cint((maxredcount+maxpagesize-1)/maxpagesize)
  rs.pagesize = maxpagesize
  pageno=Request("pageno")
  If IsEmpty(pageno) Or Not IsNumeric(pageno) Or CInt(pageno)<1 Or CInt(pageno)>Rs.Pagecount Then
   Pageno=1
  End If
  rs.absolutePage=pageno
  End If
  On Error Resume Next
End Function
'分页函数尾
'无参数
'-------------------------------------------------------------------------------
Public Function PageFoot()
  strr="<table width=""500"" border=""0"" cellpadding=""0"" cellspacing=""0"">" & VbCrLf
  strr=strr&" <tr>" & VbCrLf
  strr=strr&" <td valign=""top""><div align=""Right"">"
'大于1页才会显示首页和上一页(可选)
' If pageno>1 Then
   strr=strr&"<a href=""?pageno=1"" title=""首页""><font face = Webdings>9</font></a>"
   strr=strr&" "
   strr=strr&"<a href=""?pageno="&pageno-1&""" title=""上一页""><font face = Webdings>7</font></a>"
' End If
  strr=strr&" "&pageno&" "
'小于最大页数才会显示下一页和尾页(可选)
' If pageno<maxpageno Then
   strr=strr&"<a href=""?pageno="&pageno+1&""" title=""下一页""><font face = Webdings>8</font></a>"
   strr=strr&" "
   strr=strr&"<a href=""?pageno="&maxpageno&""" title=""""><font face = Webdings>:</font></a>"
' End If
  strr=strr&" "
  strr=strr&(pageno-1)*maxpagesize+1&"/"&maxredcount&"条记录"
  strr=strr&" "
  strr=strr&pageno&"/"&maxpageno&"页"
  strr=strr&"</div></td>" & VbCrLf
  strr=strr&" </tr>" & vbCrLf
  strr=strr&"</table>"
  PageFoot=strr
End Function
'进行行列格式化函数
'TableWidth =表格宽度
'TableHeight =表格高度(因浏览器不同可能无效)
'-------------------------------------------------------------------------------
Public Function FormatCRtable(TableWidth,TableHeight)
  Dim i,strr
  i=0
  strr=""
  strr=strr&"<table width="""&TableWidth&""" border=""0"" cellspacing=""0"" cellpadding=""0"">" & vbCrLf
  strr=strr&" <tr>" & VbCrLf
  If maxredcount>0 Then
   Do While i<maxpagesize
   i=i+1
   If Not Rs.eof Then
   strr=strr&" <td width="""&TableWidth/Cols&""" height="""&Tableheight/Rows&""">有记录则进行输出</td>" & vbCrLf
   Rs.movenext
   Else
   strr=strr&" <td width="""&TableWidth/Cols&""" height="""&Tableheight/Rows&""">记录集不足时补余</td>" & VbCrLf
   End If
   If i Mod Cols = 0 Then
   strr=strr&" </tr>" & VbCrLf
   strr=strr&" <tr>" & vbCrLf
   End If
   Loop
  Else
   strr=strr&"<td height="""&TableWidth&""" valign=""top"">目前没有记录集</td>"
  End if
  strr=strr&" </tr>" & VbCrLf
  strr=strr&"</table>" & VbCrLf
  FormatCRtable=strr
End Function
%>
代码还有很多不足,而且写的也不是很严谨,见笑了。
以后可以会改为Class
转自:http://jorkin.reallydo.com/article.asp?id=15