Posted By

neal_grosskopf on 03/18/09


Tagged

function ASP


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

neal_grosskopf
nelda751
benrudolph
asifrizvigmailcom
britevents


Simple Function To Return Recordset Results as Table In HTML


 / Published in: ASP
 

URL: http://www.nealgrosskopf.com/tech/thread.asp?pid=40

A quick and easy function that will output table column names and loop through your SQL recordset results outputting it into a HTML table.

  1. function ReturnHTMLTable(query)
  2.  
  3. set rs = cn.Execute(query)
  4.  
  5. rs.MoveFirst
  6. response.Write "<table class=""data"" cols=""" & rs.Fields.Count & """>"
  7. response.Write "<tr>"
  8.  
  9. For Each oField In rs.Fields
  10. response.Write "<th>" & oField.Name & "</th>"
  11. Next
  12.  
  13. response.Write "</tr>"
  14.  
  15. Do While Not rs.EOF
  16.  
  17. response.Write "<tr>"
  18.  
  19. For Each oField In rs.Fields
  20.  
  21. response.Write "<td>"
  22.  
  23. If IsNull(oField) Then
  24. response.Write " "
  25. Else
  26. response.Write oField.Value
  27. End If
  28.  
  29. response.Write "</td>"
  30.  
  31. Next
  32. rs.MoveNext
  33.  
  34. response.Write "</tr>"
  35.  
  36. Loop
  37.  
  38. response.Write "</table>"
  39.  
  40. end function

Report this snippet  

You need to login to post a comment.