`

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

    博客分类:
  • Asp
阅读更多

没有用正常的循环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
分享到:
评论

相关推荐

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

    没有用正常的循环tr内循环td的方法,所以就没有计算最后一页的记录集数量。 但当记录集不足时也同样能够自动补空行空列,如有不足请指出,谢谢。 使用方法很简单: 代码如下:&lt;&#37; showData(“查询语名”) ...

    ASP.NET 3.5 开发大全

    2.3.6 创建和使用常量 2.3.7 创建并使用枚举 2.3.8 类型转换 2.4 编写表达式 2.4.1 表达式和运算符 2.4.2 运算符的优先级 2.5 使用条件语句 2.5.1 if语句的使用方法 2.5.2 switch选择语句的使用 2.6 使用循环语句 ...

    ASP.NET 3.5 开发大全11-15

    2.3.6 创建和使用常量 2.3.7 创建并使用枚举 2.3.8 类型转换 2.4 编写表达式 2.4.1 表达式和运算符 2.4.2 运算符的优先级 2.5 使用条件语句 2.5.1 if语句的使用方法 2.5.2 switch选择语句的使用 2.6 使用循环语句 ...

    ASP.NET 3.5 开发大全1-5

    2.3.6 创建和使用常量 2.3.7 创建并使用枚举 2.3.8 类型转换 2.4 编写表达式 2.4.1 表达式和运算符 2.4.2 运算符的优先级 2.5 使用条件语句 2.5.1 if语句的使用方法 2.5.2 switch选择语句的使用 2.6 使用循环语句 ...

    十天学会ASP.net--我认为ASP.NET比ASP难很多,希望大家做好准备

    虽然说学习ASP.NET不需要任何ASP基础,但是我觉得如果大家ASP不会,还是先看一下【十天学会ASP教程】,大家所需要了解的不是ASP的程序怎么写,而是怎么构建服务器,怎么使用HTML表单,同时对SQL语句有一个基础和理解...

    ASP.NET3.5从入门到精通

    2.3.6 创建和使用常量 2.3.7 创建并使用枚举 2.3.8 类型转换 2.4 编写表达式 2.4.1 表达式和运算符 2.4.2 运算符的优先级 2.5 使用条件语句 2.5.1 if 语句的使用方法 2.5.2 switch 选择语句的使用 2.6 使用循环语句 ...

    ASP.NET 3.5 开发大全word课件

    2.3.6 创建和使用常量 2.3.7 创建并使用枚举 2.3.8 类型转换 2.4 编写表达式 2.4.1 表达式和运算符 2.4.2 运算符的优先级 2.5 使用条件语句 2.5.1 if语句的使用方法 2.5.2 switch选择语句的使用 2.6 使用循环语句 ...

    经典全面的SQL语句大全

     INTERSECT 运算符通过只包括 TABLE1 和 TABLE2 中都有的行并消除所有重复行而派生出一个结果表。当 ALL 随 INTERSECT 一起使用时 (INTERSECT ALL),不消除重复行。  注:使用运算词的几个查询结果行必须是一致的...

    ASPNET35开发大全第一章

    2.3.6 创建和使用常量 2.3.7 创建并使用枚举 2.3.8 类型转换 2.4 编写表达式 2.4.1 表达式和运算符 2.4.2 运算符的优先级 2.5 使用条件语句 2.5.1 if语句的使用方法 2.5.2 switch选择语句的使用 2.6 使用循环语句 ...

Global site tag (gtag.js) - Google Analytics