The paging display of database records on the client----2

Source: Internet
Author: User
Tags array vbscript class client
Pagination | client | data | database | show | Execute Create a paging class

Keep in mind that the entire application here includes only one ASP page. When this ASP page is accessed, it creates all the client JavaScript code that is required to perform the paging of records. To simplify the process, I created a VBScript class to handle this feature. When using this class, the developer simply passes in the recordset that he wants to page through the visitor's Web browser. For the use of classes, read about using classes in VBScript.

I named this class Dhtmlgetrows, which contains two properties and one method. Two properties are:

1, Recsperpage: Determine how many records each page display.

2, Thstring: Through an HTML table to show this is the result of pagination; This property allows you to specify a string for the title of the table.

A single approach is generatehtml (recordsetobject), which returns complete HTML for the paging application: Client JavaScript code and the required div tag. This method requires only one parameter recordsetobject, which should be a Recordset object that populates the database data that you want to display in a paging format.

The code for this class is quite long, and most of the code simply returns the JavaScript code for the client. The following is the code for the class:

<%
Class dhtmlgetrows

' ******* PRIVATE member VARIABLES **********
Private Irecsperpage
Private strthstring
'*******************************************

' ************ Initialize Event *************
Private Sub Class_Initialize ()
Irecsperpage = Ten ' 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 ' using
Stroutput = stroutput & vbCrLf & vbCrLf & "var 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 & "A/+" & _
Irecsperpage & "& VbCrLf &" last + + & Irecsperpage & _
VbCrLf & "}" & VbCrLf & "Else If" (ival = 1) {"& VbCrLf & VbTab & _
"& Irecsperpage &"; "& VbCrLf & VbTab &" Last-= "& _
Irecsperpage & ";" & VbCrLf & "}" & VbCrLf & _
VbCrLf & vbCrLf & "var txt = ';" & VbCrLf & _
"TXT + + ' <table border=" "1" "" > "" & VbCrLf

'



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.