Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > ASP > 在客户端执行数据库记录的分页显示----2
【标  题】:在客户端执行数据库记录的分页显示----2
【关键字】:数据库,分页,客户端
【来  源】:网络

在客户端执行数据库记录的分页显示----2

Your Ad Here 创建一个分页类

要记住,这里举例的整个应用程序只包括一个ASP页面。当这个ASP页面被访问时,它将创建执行记录分页需要的所有客户端JavaScript代码。为简化这个过程,我创建了一个VBScript类来处理这个功能。使用这个类的时候,开发人员只需将他希望在访问者的Web浏览器上进行分页的记录集传递进来即可。关于类的使用,请阅读在VBScript中使用类。

我将这个类命名为dhtmlGetRows,它包含两个属性和一个方法。两个属性是:

1、 RecsPerPage:确定每一页显示多少个记录。

2、 THString:通过一个HTML表格显示这个进行了分页的结果;这个属性允许你为表格的标题指定一个字串。

单一的方法是GenerateHTML(RecordsetObject),它为分页应用程序返回完整的HTML:客户端JavaScript代码和需要的DIV 标记。这个方法只需要一个参数RecordsetObject,它应该是一个记录集对象,其中填充了你希望在一个分页格式中显示的数据库数据。

这个类的代码相当长,并且大部分代码都只是返回客户端的JavaScript代码。下面是类的代码:

<%
Class dhtmlGetRows

'******* PRIVATE MEMBER VARIABLES **********
Private iRecsPerPage
Private strTHString
'*******************************************

'************ Initialize Event *************
Private Sub Class_Initialize()
iRecsPerPage = 10 'assign a default value
End Sub
'*******************************************


'************ PROPERTY LET/GET *************
Public Property Let THString(strValue)
'Replace all apostrophes with \'
strTHString = Replace(strValue, "'", "\'")
End Property

Public Property Get THString()
THString = strTHString
End Property


Public Property Let RecsPerPage(iValue)
If iValue > 0 and IsNumeric(iValue) then
iRecsPerPage = CInt(iValue)
End If
End Property

Public Property Get RecsPerPage()
RecsPerPage = iRecsPerPage
End Property
'*******************************************


'**************** METHODS ******************
Public Function GenerateHTML(objRS)

'Begin by getting an array of the data
Dim aValues
aValues = objRS.GetRows()

'Find the value of rows and columns
Dim iCols, iRows
iCols = UBound(aValues, 1)
iRows = UBound(aValues, 2)

Dim strOutput
'Display the initial script block
strOutput = "<script language=""javascript"">" & vbCrLf & _
"var tableRow = new Array(" & iRows & ");" & vbCrLf & vbCrLf

Dim iLoop, iColLoop, strTmp
For iLoop = 0 to iRows
strOutput = strOutput & "tableRow[" & iLoop & "] = '<tr>"

For iColLoop = 0 to iCols
'Fix apostrophes
strTmp = Replace(aValues(iColLoop, iLoop),"'", "\'")

'Remove carraige returns
strTmp = Replace(strTmp, vbCrLf, "")

strOutput = strOutput & "<td>" & strTmp & "</td>"
Next 'iColLoop

strOutput = strOutput & "</tr>';" & vbCrLf
Next 'iLoop

'Init global varaibles and find out what browser the user is using
strOutput = strOutput & vbCrLf & vbCrLf & "var first = 0;" & vbCrLf & _
"var last = " & iRecsPerPage & ";" & vbCrLf & _
"var mynav;" & vbCrLf & "if (navigator.appName == ""Netscape"")" & _
vbCrLf & vbTab & "mynav = ""NS"";" & vbCrLf & _
"if (navigator.appName == ""Microsoft Internet Explorer"")" & _
vbCrLf & vbTab & "mynav = ""IE"";" & vbCrLf & _
vbCrLf & "</script>" & vbCrLf & vbCrLf

'Now display the HTML table
strOutput = strOutput & vbCrLf & "<div id=""grid""> </div>" & vbCrLf & _
vbCrLf & vbCrLf & "<script language=""javascript"">" & vbCrLf


'Write the nav function
strOutput = strOutput & "function nav(iVal) {" & vbCrLf & _
"// do we want to move forward or backwards?" & vbCrLf & _
"if (iVal == 1) { " & vbCrLf & vbTab & "first += " & _
iRecsPerPage & ";" & vbCrLf & "last += " & iRecsPerPage & _
vbCrLf & "}" & vbCrLf & "else if (iVal == -1) { " & vbCrLf & vbTab & _
"first -= " & iRecsPerPage & ";" & vbCrLf & vbTab & "last -= " & _
iRecsPerPage & ";" & vbCrLf & "}" & vbCrLf & _
vbCrLf & vbCrLf & "var txt = '';" & vbCrLf & _
"txt += '<table border=""1"">';" & vbCrLf

'Do we need to add a TH string?
If Len(strTHString) > 0 then
strOutput = strOutput & "txt += '<tr>" & strTHString & "</tr>';" & vbCrLf
End If

strOutput = strOutput & "for (var iLoop = first; iLoop < last; iLoop++)" & vbCrLf & _
vbTab & "if (iLoop <= " & iRows & ") txt += tableRow[iLoop];" & vbCrLf & _
"txt += '</table>';" & vbCrLf & vbCrLf

'Now, show next/prev links if applicable
strOutput = strOutput & "if (first > 0) // show prev link" & vbCrLf & _
vbTab & "txt += '<a href=""javascript:nav(-1);"">Prev " & _
iRecsPerPage & "</a> ';" & vbCrLf & vbCrLf & _
"if (last <= " & iRows & ") // show next link" & vbCrLf & vbTab & _
"txt += '<a href=""javascript:nav(1);"">Next " & _
iRecsPerPage & "</a>';" & vbCrLf & vbCrLf

'Write out the new HTML content to the DIV tag
strOutput = strOutput & "// write out the the DIV tag depending on browser..." & vbCrLf & _
"if (mynav == ""NS"") {" & vbCrLf & vbTab & _
"document.layers['grid'].document.write(txt);" & vbCrLf & vbTab & _
"document.close();" & vbCrLf & "}" & vbCrLf & vbCrLf & _
"if (mynav == ""IE"")" & vbCrLf & vbTab & _
"document.all['grid'].innerHTML = txt;" & vbCrLf & vbCrLf & _
"}" & vbCrLf & vbCrLf

strOutput = strOutput & "nav(0);" & vbCrLf & "</script>"

GenerateHTML = strOutput
End Function
'*******************************************
End Class

%>

在客户端执行数据库记录的分页显示----1:【上一篇】
在客户端执行数据库记录的分页显示----3:【下一篇】
【相关文章】
没有相关文章
【随机文章】
  • VI的全局替换命令
  • DVB技术
  • Apache内存池内幕(2)
  • 知道为啥中国教育搞不上去,这就是原因.
  • 全屏幕编辑软件的编写(C语言)04
  • Fedora Core 4技巧与窍门
  • 理解STL---understanding stl
  • 利用新一代MSTP技术优化城域光传送网
  • Tomcat5中文问题解决之道
  • 通过禁止使用xp_cmdShell提高安全
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.