[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<br>");         
      } //-- if
       
      var rgxLink = /\./gi; 
      if (rgxLink.test(sLink) == false) 
      { 
        fnErrorMessage( 
          "fnDisplayRecordset", "sLink", 
          "The parameter must be a valid (relative/ absolute) URL<br>");         
      } //-- if
 
      bMakeLink = true; 
    } /* if */ 
     
    //dbug(bMakeLink); 
    if (adoRs == null) 
    { 
      fnErrorMessage( 
        "fnDisplayRecordset", "adoRs", 
        "A required parameter was omitted<br>"); 
    } /* if adoRS is null */ 
     
    if (typeof(adoRs) != "object") 
    { 
      fnErrorMessage( 
        "fnDisplayRecordset", "adoRs", 
        "The parameter must be an ADO recordset object<br>"); 
    } /* 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 +=  
      "<table    align = 'center' \n"; 
    if (aaFormatInfo[0] == true) 
      { sOutput += "     border = '1' \n"; } 
    else 
      { sOutput += "     border = '0' \n"; } 
       
    sOutput += 
      "    cellpadding = '1'      cellspacing = '1'> \n" +   
      "<tr> \n" +
      "   <td><i>Row Number</i></td> \n";         

    for (var ii = 0; ii < adoRs.Fields.Count; ii++) 
    {  
       sOutput +=  
         "   <td><b><font color = \"" + aaFormatInfo[2] + "\">" + 
         Server.HTMLEncode(adoRs.Fields.Item(ii).Name + " ") +  
        "</font></b></td>\n"; 
    } /* for */          
    sOutput += "</tr>\n"; 
     
    iRowCounter = 1; 
    while (!adoRs.EOF) 
    {   
      sOutput += "<tr>\n"; 
      sOutput += "   <td>" + iRowCounter + "</td>\n"; 
      for (var ii = 0; ii < adoRs.Fields.Count; ii++) 
      {                  
        if ((iRowCounter % 2) == 1) 
          { sOutput += "<td bgcolor = \"" + aaFormatInfo[3] + "\"> \n"; } 
        else 
          { sOutput += "<td bgcolor = \"" + aaFormatInfo[1] + "\"> \n"; }  
        if ((bMakeLink == true) && (ii == 0)) 
        { 
          sOutput +=  
            "<a  href = '" + sLink + "?" + 
            Server.URLEncode(adoRs.Fields.Item(0).Name) + "=" + 
            Server.URLEncode(adoRs.Fields.Item(0).Value) + "'>"; 
        } /* if */ 
         
        //***HTMLencode crashes if given [null] 
        sTemp = Server.HTMLEncode(adoRs.Fields.Item(ii).Value + " ");  
                          
        sOutput +=  
          sTemp + "\n"; 
        if (bMakeLink && (ii == 0)) 
        { 
          sOutput += "</a>" 
        } /* if */ 
           
        sOutput += "   </td>\n"; 
      } /* for */          
      sOutput += "</tr>\n"; 
      adoRs.Movenext(); 
      iRowCounter++; 
    } /* while not eof */ 
     
    sOutput +=  
      "</table>"; 
       
    return sOutput; 
  } /* fnDisplayRecordset */  

[/script]