我用ASP寫的m行n列的函數(shù),動(dòng)態(tài)輸出創(chuàng)建TABLE行列
更新時(shí)間:2007年02月07日 00:00:00 作者:
沒有用正常的循環(huán)tr內(nèi)循環(huán)td的方法,所以就沒有計(jì)算最后一頁(yè)的記錄集數(shù)量。
但當(dāng)記錄集不足時(shí)也同樣能夠自動(dòng)補(bǔ)空行空列,如有不足請(qǐng)指出,謝謝。
使用方法很簡(jiǎn)單:
<%
showData("查詢語(yǔ)名")
Call pagehead(行數(shù),列數(shù))
'-------------------------------------------------------------------------------
'可以把下面的Response.Write()寫到函數(shù)里面,看個(gè)人的愛好了。
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
'初始化分頁(yè)
'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
'分頁(yè)函數(shù)尾
'無(wú)參數(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頁(yè)才會(huì)顯示首頁(yè)和上一頁(yè)(可選)
' If pageno>1 Then
strr=strr&"<a href=""?pageno=1"" title=""首頁(yè)""><font face = Webdings>9</font></a>"
strr=strr&" "
strr=strr&"<a href=""?pageno="&pageno-1&""" title=""上一頁(yè)""><font face = Webdings>7</font></a>"
' End If
strr=strr&" "&pageno&" "
'小于最大頁(yè)數(shù)才會(huì)顯示下一頁(yè)和尾頁(yè)(可選)
' If pageno<maxpageno Then
strr=strr&"<a href=""?pageno="&pageno+1&""" title=""下一頁(yè)""><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&"頁(yè)"
strr=strr&"</div></td>" & VbCrLf
strr=strr&" </tr>" & vbCrLf
strr=strr&"</table>"
PageFoot=strr
End Function
'進(jìn)行行列格式化函數(shù)
'TableWidth =表格寬度
'TableHeight =表格高度(因?yàn)g覽器不同可能無(wú)效)
'-------------------------------------------------------------------------------
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&""">有記錄則進(jìn)行輸出</td>" & vbCrLf
Rs.movenext
Else
strr=strr&" <td width="""&TableWidth/Cols&""" height="""&Tableheight/Rows&""">記錄集不足時(shí)補(bǔ)余</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),見笑了。
以后可以會(huì)改為Class
轉(zhuǎn)自:http://jorkin.reallydo.com/article.asp?id=15
但當(dāng)記錄集不足時(shí)也同樣能夠自動(dòng)補(bǔ)空行空列,如有不足請(qǐng)指出,謝謝。
使用方法很簡(jiǎn)單:
復(fù)制代碼 代碼如下:
<%
showData("查詢語(yǔ)名")
Call pagehead(行數(shù),列數(shù))
'-------------------------------------------------------------------------------
'可以把下面的Response.Write()寫到函數(shù)里面,看個(gè)人的愛好了。
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
'初始化分頁(yè)
'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
'分頁(yè)函數(shù)尾
'無(wú)參數(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頁(yè)才會(huì)顯示首頁(yè)和上一頁(yè)(可選)
' If pageno>1 Then
strr=strr&"<a href=""?pageno=1"" title=""首頁(yè)""><font face = Webdings>9</font></a>"
strr=strr&" "
strr=strr&"<a href=""?pageno="&pageno-1&""" title=""上一頁(yè)""><font face = Webdings>7</font></a>"
' End If
strr=strr&" "&pageno&" "
'小于最大頁(yè)數(shù)才會(huì)顯示下一頁(yè)和尾頁(yè)(可選)
' If pageno<maxpageno Then
strr=strr&"<a href=""?pageno="&pageno+1&""" title=""下一頁(yè)""><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&"頁(yè)"
strr=strr&"</div></td>" & VbCrLf
strr=strr&" </tr>" & vbCrLf
strr=strr&"</table>"
PageFoot=strr
End Function
'進(jìn)行行列格式化函數(shù)
'TableWidth =表格寬度
'TableHeight =表格高度(因?yàn)g覽器不同可能無(wú)效)
'-------------------------------------------------------------------------------
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&""">有記錄則進(jìn)行輸出</td>" & vbCrLf
Rs.movenext
Else
strr=strr&" <td width="""&TableWidth/Cols&""" height="""&Tableheight/Rows&""">記錄集不足時(shí)補(bǔ)余</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
%>
以后可以會(huì)改為Class
轉(zhuǎn)自:http://jorkin.reallydo.com/article.asp?id=15
相關(guān)文章
asp連接access、sql數(shù)據(jù)庫(kù)代碼及數(shù)據(jù)庫(kù)操作代碼
asp連接access、sql數(shù)據(jù)庫(kù)代碼及數(shù)據(jù)庫(kù)操作代碼,需要的朋友可以參考下2012-10-10非常不錯(cuò)的列出sql服務(wù)器上所有數(shù)據(jù)庫(kù)的asp代碼
非常不錯(cuò)的列出sql服務(wù)器上所有數(shù)據(jù)庫(kù)的asp代碼...2006-12-12生成EAN13標(biāo)準(zhǔn)的條形碼的ASP代碼實(shí)例
生成EAN13標(biāo)準(zhǔn)的條形碼的ASP代碼實(shí)例...2007-10-10ASP生成隨機(jī)數(shù) ASP生成不重復(fù)隨機(jī)數(shù)
這篇文章主要介紹了ASP生成不重復(fù)隨機(jī)數(shù)的方法,需要的朋友可以參考下2014-05-05asp ajax注冊(cè)驗(yàn)證之 防止用戶名輸入空格
注冊(cè)驗(yàn)證之防止用戶名輸入空格,asp批量替換特殊字符函數(shù)代碼2009-08-08ASP UTF-8編碼生成靜態(tài)網(wǎng)頁(yè)的函數(shù)
按照“FSO生成的網(wǎng)頁(yè)文件默認(rèn)編碼格式以及轉(zhuǎn)換成UTF-8編碼方法”,編寫函數(shù)采用用Adodb.Stream對(duì)象,成功生成UTF-8網(wǎng)頁(yè)文件。2009-11-11利用Split函數(shù)進(jìn)行多關(guān)鍵字檢索
利用Split函數(shù)進(jìn)行多關(guān)鍵字檢索...2006-07-07