<% 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, but make sure field is not null if Not IsNull(aValues(iColLoop, iLoop)) then strTmp = Replace(aValues(iColLoop, iLoop),"'", "\'") 'Remove carraige returns strTmp = Replace(strTmp, vbCrLf, "") strOutput = strOutput & "<td>" & strTmp & "</td>" else strOutput = strOutput & "<td>&nbsp;</td>" end if 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"">&nbsp;</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 %>