[script language = jscript runat = server] /*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--* * FUNCTION: fnDisplayRecordset() * DESCRIPTION: This function displays the contents of an ADO recordset (derived from a query on a relational database) on a web page. The function also allows one of the display columns to be 'hyperlinked' with a key value submitted in the query string. This allows this function to be used in conjunction with another function which displays a single resultset record on an html/asp page. (For example: fnDisplayRecord() ). * PARAMETERS: -adoRs {ADO Recordset, required} The recordset to display -sLink {String, optional} A string specifying a page to link each record of the recordet to. -aaFormatInfo {Array, optional} An array containing all the colour and formatting information for the display: STRUCTURE: fHasBorder, sTableBgColour, sFontColour, sAlternatingRowColour * STATUS: working, tested a little * WORKING HISTORY: 27th Nov 2000-- Revised this file * DEPENDENCIES: fnErrorMessage(), fnConvertArray() ? * DOCUMENTED AT: http://www.geocities.com/matth3wbishop/eg/asp/fnDisplayRecordset.doc (?) * CODE LOCATION: http://www.geocities.com/matth3wbishop/eg/asp/fnDisplayRecordset.txt * TO DO: allow a better style, ie no border, alternating colours * NOTES: *--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/ function fnDisplayRecordset(adoRs, sLink, aaFormatInfo, aaColumnHeadings) { var sOutput = new String(""); var iRowCounter; //***provides a row index var sTemp; //***Avoids HTMLencode null problem var bMakeLink = new Boolean(false); //adoRs.GetRows(); //debug( //***ERROR HANDLE, PROVIDE DEFAULTS if (sLink != null) { if (typeof(sLink) != "string") { fnErrorMessage( "fnDisplayRecordset", "sLink", "The parameter must be a string
"); } //-- if var rgxLink = /\./gi; if (rgxLink.test(sLink) == false) { fnErrorMessage( "fnDisplayRecordset", "sLink", "The parameter must be a valid (relative/ absolute) URL
"); } //-- if bMakeLink = true; } /* if */ //dbug(bMakeLink); if (adoRs == null) { fnErrorMessage( "fnDisplayRecordset", "adoRs", "A required parameter was omitted
"); } /* if adoRS is null */ if (typeof(adoRs) != "object") { fnErrorMessage( "fnDisplayRecordset", "adoRs", "The parameter must be an ADO recordset object
"); } /* if adoRS not an object */ //***Handle Format Information Param INCOMPLETE if (aaFormatInfo == null) { var aaFormatInfo = new Array(false, "white", "black", "gray"); } else { aaFormatInfo = aaFormatInfo; //--aaFormatInfo = fnConvertArray(aaFormatInfo); if (aaFormatInfo[1] == null) { aaFormatInfo[1] = false; } if (aaFormatInfo[2] == null) { aaFormatInfo[2] = "white"; } if (aaFormatInfo[3] == null) { aaFormatInfo[3] = "black"; } if (aaFormatInfo[4] == null) { aaFormatInfo[4] = "gray"; } } /* if */ if (aaColumnHeadings == null) { var aaColumnHeadings = new Array(); } else { aaColumnHeadings = fnConvertArray(aaColumnHeadings); //*** supply defaults here } /* if */ if (adoRs.EOF || adoRs.BOF) { return "No Data"; } adoRs.MoveFirst(); //***END ERROR/ DEFAULT HANDLING sOutput += " \n" + " \n"; for (var ii = 0; ii < adoRs.Fields.Count; ii++) { sOutput += " \n"; } /* for */ sOutput += "\n"; iRowCounter = 1; while (!adoRs.EOF) { sOutput += "\n"; sOutput += " \n"; for (var ii = 0; ii < adoRs.Fields.Count; ii++) { if ((iRowCounter % 2) == 1) { sOutput += "\n"; } /* for */ sOutput += "\n"; adoRs.Movenext(); iRowCounter++; } /* while not eof */ sOutput += "
Row Number" + Server.HTMLEncode(adoRs.Fields.Item(ii).Name + " ") + "
" + iRowCounter + " \n"; } else { sOutput += " \n"; } if ((bMakeLink == true) && (ii == 0)) { sOutput += ""; } /* if */ //***HTMLencode crashes if given [null] sTemp = Server.HTMLEncode(adoRs.Fields.Item(ii).Value + " "); sOutput += sTemp + "\n"; if (bMakeLink && (ii == 0)) { sOutput += "" } /* if */ sOutput += "
"; return sOutput; } /* fnDisplayRecordset */ [/script]