By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

What is the best way to make a table on asp page?

P: 67
Hi,

I am trying to make my table on an asp page cleaner.

Right now, I have an html table on my page that draws information from my database. The customer can enter the following on the registration page:

Provider name: "drop down menu list" option named "provider1"
If name not listed, enter name: "text box" named "other"
Provider 2 name: "drop down menu list" option named "provider2"
If name not listed, enter name: "text box" named "other2"

The problem I am having is when the table shows up on the asp account page, there is akward spacing. For instance, if the user only finds his provider in line 1 but has to enter text for provider 2, there is a larger border between these. If they only enter one provider and leave the 2nd blank, the bottom of the table is extended down but nothing is there except the solid background color.

I am wondering if there is a better way to make a table that recognizes the information entered and resizes the table depending on the information entered.

Sorry if this is very confusing, I am having a heck of a time explaining this. If there is a way to show pictures on here, I'll gladly post a picture of my table if you can tell me how.

Thanks for any insight - Jerry
Dec 1 '08 #1
Share this Question
Share on Google+
10 Replies


CroCrew
Expert 100+
P: 563
Hello Jerry,

Could you post your code. That will help in getting you an answer.

Thanks,
CroCrew~
Dec 1 '08 #2

P: 67
Here is my code. Please take note, the customer will either enter a text into the "program" or the "other" text boxes. If they enter 5 programs, the table looks great. If they enter less, there is extra space at the bottom and if they enter any "other" then the border lines are much fatter. Any ideas how to clean this up a bit? Thanks

Expand|Select|Wrap|Line Numbers
  1. <center><table width="30%" border="0" cellpadding="5" cellspacing="0"> 
  2. <tr><table border="2" cellpadding="5" cellspacing="3" bordercolor="black" bgcolor="black">
  3. <tr bgcolor="black">
  4. <th colspan="2"><font color="white" face="perpetua titling mt"><b>Title</b></font></th>
  5. <tr bgcolor="silver">
  6. <th>Program</th>
  7. <th>Points</th></tr>
  8. <tr valign="top" bgcolor="white">
  9. <td><%=objRS("Program1")%></td>
  10. <td><%=objRS("Points1")%></td></tr>
  11. <tr valign="top" bgcolor="white">
  12. <td><%=objRS("Other1")%></td>
  13. <td><%=objRS("Points1")%></td></tr>
  14. <tr valign="top" bgcolor="white">
  15. <td><%=objRS("Program2")%></td>
  16. <td><%=objRS("Points2")%></td></tr>
  17. <tr valign="top" bgcolor="white">
  18. <td><%=objRS("Other2")%></td>
  19. <td><%=objRS("Points2")%></td></tr>
  20. <tr valign="top" bgcolor="white">
  21. <td><%=objRS("Program3")%></td>
  22. <td><%=objRS("Points3")%></td></tr>
  23. <tr valign="top" bgcolor="white">
  24. <td><%=objRS("Other3")%></td>
  25. <td><%=objRS("Points3")%></td></tr>
  26. <tr valign="top" bgcolor="white">
  27. <td><%=objRS("Program4")%></td>
  28. <td><%=objRS("Points4")%></td></tr>
  29. <tr valign="top" bgcolor="white">
  30. <td><%=objRS("Other4")%></td>
  31. <td><%=objRS("Points4")%></td></tr>
  32. <tr valign="top" bgcolor="white">
  33. <td><%=objRS("Program5")%></td>
  34. <td><%=objRS("Points5")%></td></tr>
  35. <tr valign="top" bgcolor="white">
  36. <td><%=objRS("Other5")%></td>
  37. <td><%=objRS("Points5")%></td></tr>
  38. </table></td>
Dec 2 '08 #3

CroCrew
Expert 100+
P: 563
Hello Jerrydigital,

Itís a bit confusing what your asking help for but I think this might help you out. It seems that you have built the table and are just plopping the recordset values in the cells. Thus; if programs 1, 2, 3, 4, 5 where entered then all the cells in each row would be filled. But letís say if someone entered just programs 1, 2, 4, 5 then there would be a blank row between programs 2 and 4.

Without seeing all your code the only advice that I could give you is to check for a value in the recordset before building the row. Something like this for each row:

Expand|Select|Wrap|Line Numbers
  1. <%
  2.     If (LEN(objRS("Program3")) > 0) Then
  3.         Response.Write("<tr valign='top' bgcolor='white'>")
  4.             Response.Write("<td>" & objRS("Program3") & "</td>")
  5.             Response.Write("<td>" & objRS("Points3") & "</td>")
  6.         Response.Write("</tr>")
  7.     End If
  8. %>
  9.  
Hope this helps,
CroCrew~
Dec 2 '08 #4

P: 67
Thanks CroCrew,

I tried to implement your code but I got the following error:

Microsoft VBScript compilation error '800a0408'
Invalid character
/accountpage.asp, line 106
If LEN(objRS("AProgram1")) > 0 Then


I am sure this didn't work because of my lack of knowledge but I have posted my entire code for this page below for your review.

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <!--#include virtual="/adovbs.inc"-->
  4.  
  5. <%
  6. If session("email") = "" Then
  7.     Response.Redirect "login.html"
  8.     Response.End
  9. Else
  10.     Response.Write "You are logged in as " & session("email") & " " & "<a href='logout.asp'>" & "(Logout)" & "</a>"
  11.  
  12. End If
  13.  
  14. Dim oConn
  15. Dim connectstr, sDSNDir, dsn_name
  16.  
  17. dsn_name = "table.dsn"
  18.  
  19. sDSNDir = Server.MapPath("/_dsn")
  20. connectstr = "filedsn=" & sDSNDir & "/" & dsn_name
  21.  
  22. Set oConn = Server.CreateObject("ADODB.Connection")
  23. oConn.Open = connectstr
  24.  
  25. Dim strSQL, strEmail
  26. Dim bolFound
  27.  
  28. strEmail = session("email")
  29. strEmail = Replace(strEmail, "'", "''")
  30.  
  31. strSQL = "SELECT * From TABLE"
  32.  
  33. Dim objRS
  34. Set objRS = Server.CreateObject("ADODB.Recordset")
  35. objRS.Open strSQL, oConn
  36. bolFound = False
  37.  
  38. Do While Not (objRS.EOF OR bolFound)
  39. If (StrComp(objRS("Email"),strEmail, vbTextCompare) = 0) Then
  40. BolFound = True
  41. Else
  42. objRS.MoveNext
  43. End If
  44. Loop
  45.  
  46. If Not bolFound Then
  47. objRS.Close
  48. Set objRS = Nothing
  49. oConn.Close
  50. Set oConn = Nothing
  51. Response.Redirect("login.html")
  52. Response.End
  53. End If
  54.  
  55. %>
  56.  
  57.  
  58. <html>
  59. <head><title>Programs/Points</title>
  60. </head>
  61.  
  62. <center><b><font face="comic sans ms" size="+3">Welcome <%=objRS("FirstName" )%></font></b></center>
  63. <br>
  64. <center><table width="85%"  border="0" cellpadding="5" cellspacing="0"> 
  65. <tr> 
  66. <td><center><table width="30%" border="0" cellpadding="5" cellspacing="0"> 
  67. <tr><table border="2" cellpadding="5" cellspacing="3" bordercolor="black" bgcolor="black">
  68. <tr bgcolor="black">
  69. <th colspan="2"><font color="white" face="perpetua titling mt"><b>A</b></font></th>
  70. <tr bgcolor="silver">
  71. <th>A Program</th>
  72. <th>A Points</th></tr>
  73. <tr valign="top" bgcolor="white">
  74. <td><%=objRS("AProgram1")%></td>
  75. <td><%=objRS("APoints1")%></td></tr>
  76. <tr valign="top" bgcolor="white">
  77. <td><%=objRS("OtherA1")%></td>
  78. <td><%=objRS("APoints1")%></td></tr>
  79. <tr valign="top" bgcolor="white">
  80. <td><%=objRS("AProgram2")%></td>
  81. <td><%=objRS("APoints2")%></td></tr>
  82. <tr valign="top" bgcolor="white">
  83. <td><%=objRS("OtherA2")%></td>
  84. <td><%=objRS("APoints2")%></td></tr>
  85. <tr valign="top" bgcolor="white">
  86. <td><%=objRS("AProgram3")%></td>
  87. <td><%=objRS("APoints3")%></td></tr>
  88. <tr valign="top" bgcolor="white">
  89. <td><%=objRS("OtherA3")%></td>
  90. <td><%=objRS("APoints3")%></td></tr>
  91. <tr valign="top" bgcolor="white">
  92. <td><%=objRS("AProgram4")%></td>
  93. <td><%=objRS("APoints4")%></td></tr>
  94. <tr valign="top" bgcolor="white">
  95. <td><%=objRS("OtherA4")%></td>
  96. <td><%=objRS("APoints4")%></td></tr>
  97. <tr valign="top" bgcolor="white">
  98. <td><%=objRS("AProgram5")%></td>
  99. <td><%=objRS("APoints5")%></td></tr>
  100. <tr valign="top" bgcolor="white">
  101. <td><%=objRS("OtherA5")%></td>
  102. <td><%=objRS("APoints5")%></td></tr>
  103. </table></td>
  104.  
  105. <td><center><table width="30%" border="0" cellpadding="5" cellspacing="0">
  106. <tr><table border="2" cellpadding="5" cellspacing="3" bordercolor="black" bgcolor="black">
  107. <tr bgcolor="#000000">
  108. <th colspan="2"><font color="white" face="perpetua titling mt"><b>B</b></font></th>
  109. <tr bgcolor="silver">
  110. <th>B Program</th>
  111. <th>B Points</th></tr>
  112. <tr valign="top" bgcolor="white">
  113. <td><%=objRS("BProgram1")%></td>
  114. <td><%=objRS("BPoints1")%></td></tr>
  115. <tr valign="top" bgcolor="white">
  116. <td><%=objRS("OtherB1")%></td>
  117. <td><%=objRS("BPoints1")%></td></tr>
  118. <tr valign="top" bgcolor="white">
  119. <td><%=objRS("BProgram2")%></td>
  120. <td><%=objRS("BPoints2")%></td></tr>
  121. <tr valign="top" bgcolor="white">
  122. <td><%=objRS("OtherB2")%></td>
  123. <td><%=objRS("BPoints2")%></td></tr>
  124. <tr valign="top" bgcolor="white">
  125. <td><%=objRS("BProgram3")%></td>
  126. <td><%=objRS("BPoints3")%></td></tr>
  127. <tr valign="top" bgcolor="white">
  128. <td><%=objRS("OtherB3")%></td>
  129. <td><%=objRS("BPoints3")%></td></tr>
  130. <tr valign="top" bgcolor="white">
  131. <td><%=objRS("BProgram4")%></td>
  132. <td><%=objRS("BPoints4")%></td></tr>
  133. <tr valign="top" bgcolor="white">
  134. <td><%=objRS("OtherB4")%></td>
  135. <td><%=objRS("BPoints4")%></td></tr>
  136. <tr valign="top" bgcolor="white">
  137. <td><%=objRS("BProgram5")%></td>
  138. <td><%=objRS("BPoints5")%></td></tr>
  139. <tr valign="top" bgcolor="white">
  140. <td><%=objRS("OtherB5")%></td>
  141. <td><%=objRS("BPoints5")%></td></tr>      
  142. </table></td>
  143.  
  144. <td><center><table width="30%"  border="0" cellpadding="5" cellspacing="0"> 
  145. <tr> <table border="2" cellpadding="5" cellspacing="3" bordercolor="black" bgcolor="black">
  146. <tr bgcolor="#000000">
  147. <th colspan="2"><font color="white" face="perpetua titling mt"><b>C</b></font></th>
  148. <tr bgcolor="silver">
  149. <th>C Program</th>
  150. <th>C Points</th></tr>
  151. <tr valign="top" bgcolor="white">
  152. <td><%=objRS("CProgram1")%></td>
  153. <td><%=objRS("CPoints1")%></td></tr>
  154. <tr valign="top" bgcolor="white">
  155. <td><%=objRS("OtherC1")%></td>
  156. <td><%=objRS("CPoints1")%></td></tr>
  157. <tr valign="top" bgcolor="white">
  158. <td><%=objRS("CProgram2")%></td>
  159. <td><%=objRS("CPoints2")%></td></tr>
  160. <tr valign="top" bgcolor="white">
  161. <td><%=objRS("OtherC2")%></td>
  162. <td><%=objRS("CPoints2")%></td></tr>
  163. </table></td>     
  164. </tr> 
  165. </table>
  166. </center>
  167.  
  168. </font>
  169. </body>
  170. </html>
  171.  
  172.  
  173. <%
  174. objRS.Close
  175. Set objRS = Nothing
  176. oConn.Close
  177. Set oConn = Nothing
  178. %>
Dec 2 '08 #5

CroCrew
Expert 100+
P: 563
The code you post above, is it from the page "accountpage.asp"?

Line 106 does not have the following code that the error is displaying:

If LEN(objRS("AProgram1")) > 0 Then
Dec 2 '08 #6

P: 67
sorry for the confusion, the code above is for the table i have that is working but is uneven as i described above.

I get the error code when I substitute the following code with the code you provided:

Expand|Select|Wrap|Line Numbers
  1. <tr valign="top" bgcolor="white"> 
  2. <td><%=objRS("AProgram1")%></td> 
  3. <td><%=objRS("APoints1")%></td></tr> 
I enter this code in place of each row(the code directly above):
Expand|Select|Wrap|Line Numbers
  1. <% 
  2.     If (LEN(objRS("AProgram1")) > 0) Then 
  3.         Response.Write("<tr valign='top' bgcolor='white'>") 
  4.             Response.Write("<td>" & objRS("AProgram1") & "</td>") 
  5.             Response.Write("<td>" & objRS("APoints1") & "</td>") 
  6.         Response.Write("</tr>") 
  7.     End If 
  8. %> 
Dec 3 '08 #7

CroCrew
Expert 100+
P: 563
The first thing I would have you do is to check the punctuation marks in your VBScript, particularly look out for apostrophes and commas that do not display correctly. The error is stating that your code contains an illegal character. It can happen when you copied the script, then paste into your code. For example, to 'Remark out a line we need the apostrophe, which is ASCII character 39; however if you paste from word you may get ASCII 96. I have done that before. So try looking very closely at the code you have to make sure that there are no funny apostrophes or quotes first. I would just retype the code and not copy and paste it just to make sure.

I will keep looking for more solutions.

Hope this helps,
CroCrew~
Dec 3 '08 #8

CroCrew
Expert 100+
P: 563
Hello jerrydigital,

Could you try adding his code right before where the error is reporting the run it again.

Expand|Select|Wrap|Line Numbers
  1. Response.Write("Post This: [" & objRS("AProgram1") & "]")
  2. Response.End
  3.  
I would like to see what the value of the record is if you donít mind. After you run it could you post what is being displayed between the brackets (post the brackets too so we can see if there is any white space before and after the value).

Thanks,
CroCrew~
Dec 3 '08 #9

P: 67
CroCrew,

I repeated my substitution I mentioned in my last post, but I followed your advice and simply typed it out instead of copy and paste. And, it works perfectly. Thank you so much for your expertise. This makes my table so much more professional.

Jerry
Dec 4 '08 #10

CroCrew
Expert 100+
P: 563
Glad to help.

CroCrew~
Dec 4 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.