我用ASP写的m行n列的函数,动态输出创建TABLE行列
我用ASP写的m行n列的函数,动态输出创建TABLE行列
发布时间:2016-12-29 来源:查字典编辑
摘要:没有用正常的循环tr内循环td的方法,所以就没有计算最后一页的记录集数量。但当记录集不足时也同样能够自动补空行空列,如有不足请指出,谢谢。使...

没有用正常的循环tr内循环td的方法,所以就没有计算最后一页的记录集数量。

但当记录集不足时也同样能够自动补空行空列,如有不足请指出,谢谢。

使用方法很简单:

复制代码 代码如下:

<%

showData("查询语名")

Callpagehead(行数,列数)

'-------------------------------------------------------------------------------

'可以把下面的Response.Write()写到函数里面,看个人的爱好了。

Response.Write(FormatCRtable(表格宽度,表格高度))

Response.Write(PageFoot())

CallcloseData()

%>

函数如下:

复制代码 代码如下:

<%

'-------------------------------------------------------------------------------

'Copyright2005byJorkin.AllRightsReserved

'-------------------------------------------------------------------------------

Publicrs

Publicpageno,Cols,Rows,maxpageno,maxredcount,maxpagesize

'-------------------------------------------------------------------------------

PublicFunctionshowData(sqlstrings)

Setrs=Server.CreateObject("ADODB.Recordset")

rs.opensqlstrings,oconn,1,3

EndFunction

PublicFunctioncloseData()

rs.close

Setrs=Nothing

EndFunction

'初始化分页

'MaxRows=最大行数

'MaxCols=最大列数

'-------------------------------------------------------------------------------

PublicFunctionPageHead(MaxRows,MaxCols)

'-------------------------------------------------------------------------------

Rows=MaxRows

Cols=MaxCols

maxpagesize=1

maxredcount=0

maxpageno=0

pageno=0

'-------------------------------------------------------------------------------

maxredcount=rs.recordcount

Ifmaxredcount>0then

maxpagesize=Rows*Cols

maxpageno=Cint((maxredcount+maxpagesize-1)/maxpagesize)

rs.pagesize=maxpagesize

pageno=Request("pageno")

IfIsEmpty(pageno)OrNotIsNumeric(pageno)OrCInt(pageno)<1OrCInt(pageno)>Rs.PagecountThen

Pageno=1

EndIf

rs.absolutePage=pageno

EndIf

OnErrorResumeNext

EndFunction

'分页函数尾

'无参数

'-------------------------------------------------------------------------------

PublicFunctionPageFoot()

strr="<tablewidth=""500""border=""0""cellpadding=""0""cellspacing=""0"">"&VbCrLf

strr=strr&"<tr>"&VbCrLf

strr=strr&"<tdvalign=""top""><divalign=""Right"">"

'大于1页才会显示首页和上一页(可选)

'Ifpageno>1Then

strr=strr&"<ahref=""?pageno=1""title=""首页""><fontface=Webdings>9</font></a>"

strr=strr&""

strr=strr&"<ahref=""?pageno="&pageno-1&"""title=""上一页""><fontface=Webdings>7</font></a>"

'EndIf

strr=strr&""&pageno&""

'小于最大页数才会显示下一页和尾页(可选)

'Ifpageno<maxpagenoThen

strr=strr&"<ahref=""?pageno="&pageno+1&"""title=""下一页""><fontface=Webdings>8</font></a>"

strr=strr&""

strr=strr&"<ahref=""?pageno="&maxpageno&"""title=""""><fontface=Webdings>:</font></a>"

'EndIf

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

EndFunction

'进行行列格式化函数

'TableWidth=表格宽度

'TableHeight=表格高度(因浏览器不同可能无效)

'-------------------------------------------------------------------------------

PublicFunctionFormatCRtable(TableWidth,TableHeight)

Dimi,strr

i=0

strr=""

strr=strr&"<tablewidth="""&TableWidth&"""border=""0""cellspacing=""0""cellpadding=""0"">"&vbCrLf

strr=strr&"<tr>"&VbCrLf

Ifmaxredcount>0Then

DoWhilei<maxpagesize

i=i+1

IfNotRs.eofThen

strr=strr&"<tdwidth="""&TableWidth/Cols&"""height="""&Tableheight/Rows&""">有记录则进行输出</td>"&vbCrLf

Rs.movenext

Else

strr=strr&"<tdwidth="""&TableWidth/Cols&"""height="""&Tableheight/Rows&""">记录集不足时补余</td>"&VbCrLf

EndIf

IfiModCols=0Then

strr=strr&"</tr>"&VbCrLf

strr=strr&"<tr>"&vbCrLf

EndIf

Loop

Else

strr=strr&"<tdheight="""&TableWidth&"""valign=""top"">目前没有记录集</td>"

Endif

strr=strr&"</tr>"&VbCrLf

strr=strr&"</table>"&VbCrLf

FormatCRtable=strr

EndFunction

%>

代码还有很多不足,而且写的也不是很严谨,见笑了。

以后可以会改为Class

转自:http://jorkin.reallydo.com/article.asp?id=15

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新ASP教程学习
热门ASP教程学习
编程开发子分类