- ·上一篇文章:用ASP构建音乐服务器
- ·下一篇文章:最新的JMail(4.3版本)发送代码
在客户端执行数据库记录的分页显示
& vbCrLf & "<s cript language=""javas cript"">" & 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=""javas cript:nav(-1);"">Prev " & _
iRecsPerPage & "</a> ';" & vbCrLf & vbCrLf & _
"if (last <= " & iRows & ") // show next link" & vbCrLf & vbTab & _
"txt += '<a href=""javas cript: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 & "</s cript>"
GenerateHTML = strOutput
End Function
'*******************************************
End Class
%>
在结束之前,我想要快速地解释一下怎样在一个ASP页面中使用这个类。由于这个类只包含一个方法,因此使用这个类相当简单。你所需要做的就是创建并填充一个记录集对象,然后创建一个类的例示,并使用Response.Write输出objClassInstance.GenerateHTML(objRS)的值。
<!--#include file="dhtmlGetRows.class.asp"-->
<%
'Create and populate a Recordset
Dim objRS, objConn, strSQL
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=MyDSN"
strSQL = "SELECT TOP 25 ViewCount, Des cription " & _
"FROM tblFAQ ORDER BY ViewCount DESC"
Set objRS = objConn.Execute(strSQL)
'Create an instance of the dhtmlGetRows class
Dim objPagedResults
Set objPagedResults = new dhtmlGetRows
objPagedResults.THString = "<th>Views</th><th>FAQ Question</th>"
Response.Write objPagedResults.GenerateHTML(objRS)
'Clean up...
Set objPagedResults = Nothing
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
以上的代码片段假定dhtmlGetRows类可以在一个服务器端包含文件dhtmlGetRows.class.asp中使用。
做人要厚道,请注明转自chinazhan中国站长(www.ChinaZhan.com)。
'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=""javas cript:nav(-1);"">Prev " & _
iRecsPerPage & "</a> ';" & vbCrLf & vbCrLf & _
"if (last <= " & iRows & ") // show next link" & vbCrLf & vbTab & _
"txt += '<a href=""javas cript: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 & "</s cript>"
GenerateHTML = strOutput
End Function
'*******************************************
End Class
%>
在结束之前,我想要快速地解释一下怎样在一个ASP页面中使用这个类。由于这个类只包含一个方法,因此使用这个类相当简单。你所需要做的就是创建并填充一个记录集对象,然后创建一个类的例示,并使用Response.Write输出objClassInstance.GenerateHTML(objRS)的值。
<!--#include file="dhtmlGetRows.class.asp"-->
<%
'Create and populate a Recordset
Dim objRS, objConn, strSQL
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=MyDSN"
strSQL = "SELECT TOP 25 ViewCount, Des cription " & _
"FROM tblFAQ ORDER BY ViewCount DESC"
Set objRS = objConn.Execute(strSQL)
'Create an instance of the dhtmlGetRows class
Dim objPagedResults
Set objPagedResults = new dhtmlGetRows
objPagedResults.THString = "<th>Views</th><th>FAQ Question</th>"
Response.Write objPagedResults.GenerateHTML(objRS)
'Clean up...
Set objPagedResults = Nothing
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
以上的代码片段假定dhtmlGetRows类可以在一个服务器端包含文件dhtmlGetRows.class.asp中使用。
做人要厚道,请注明转自chinazhan中国站长(www.ChinaZhan.com)。
