我用ASP寫的m行n列的函數(shù),動態(tài)輸出創(chuàng)建TABLE行列
更新時間:2007年02月07日 00:00:00 作者:
沒有用正常的循環(huán)tr內(nèi)循環(huán)td的方法,所以就沒有計算最后一頁的記錄集數(shù)量。
但當(dāng)記錄集不足時也同樣能夠自動補空行空列,如有不足請指出,謝謝。
使用方法很簡單:
<%
showData("查詢語名")
Call pagehead(行數(shù),列數(shù))
'-------------------------------------------------------------------------------
'可以把下面的Response.Write()寫到函數(shù)里面,看個人的愛好了。
Response.Write(FormatCRtable(表格寬度,表格高度))
Response.Write(PageFoot())
Call closeData()
%>
函數(shù)如下:
<%
'-------------------------------------------------------------------------------
'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 =最大行數(shù)
'MaxCols =最大列數(shù)
'-------------------------------------------------------------------------------
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
'分頁函數(shù)尾
'無參數(shù)
'-------------------------------------------------------------------------------
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&" "
'小于最大頁數(shù)才會顯示下一頁和尾頁(可選)
' 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
'進行行列格式化函數(shù)
'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
%>
代碼還有很多不足,而且寫的也不是很嚴(yán)謹(jǐn),見笑了。
以后可以會改為Class
轉(zhuǎn)自:http://jorkin.reallydo.com/article.asp?id=15
但當(dāng)記錄集不足時也同樣能夠自動補空行空列,如有不足請指出,謝謝。
使用方法很簡單:
復(fù)制代碼 代碼如下:
<%
showData("查詢語名")
Call pagehead(行數(shù),列數(shù))
'-------------------------------------------------------------------------------
'可以把下面的Response.Write()寫到函數(shù)里面,看個人的愛好了。
Response.Write(FormatCRtable(表格寬度,表格高度))
Response.Write(PageFoot())
Call closeData()
%>
函數(shù)如下:
復(fù)制代碼 代碼如下:
<%
'-------------------------------------------------------------------------------
'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 =最大行數(shù)
'MaxCols =最大列數(shù)
'-------------------------------------------------------------------------------
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
'分頁函數(shù)尾
'無參數(shù)
'-------------------------------------------------------------------------------
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&" "
'小于最大頁數(shù)才會顯示下一頁和尾頁(可選)
' 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
'進行行列格式化函數(shù)
'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
轉(zhuǎn)自:http://jorkin.reallydo.com/article.asp?id=15
相關(guān)文章
Script.VBS.Agent.ai juan.vbs專殺
2008-01-01
asp ADO GetString函數(shù)與用GetString來提高ASP的速度
沒想到asp下有g(shù)etstring這個東西,看樣子不熟悉這塊啊,以后考慮用這個,應(yīng)該不錯,另外還有g(shù)etrows等,都是asp下提高性能不錯的函數(shù)。2007-12-12
asp實現(xiàn)防止從外部提交數(shù)據(jù)的三種方法腳本之家補充
這篇文章主要介紹了asp實現(xiàn)防止從外部提交數(shù)據(jù)的三種方法,需要的朋友可以參考下2007-11-11
ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向
這篇文章主要介紹了ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向,需要的朋友可以參考下2016-12-12

