Copy link to clipboard
Copied
Hi all,
I am a relative newbie when it comes to writing ASP code and am struggling with something that I hope somebody out there will be able to help me with.
I have an ASP detail page that displays information from as Access 2003 database regarding orders. Only information from one order is displayed on a page at a time. Each order line has 5 text fields that can be used for descriptive purposes. However not every order line uses each of the 5 description lines. My detail page currently shows a table with a repeat region to list all of the lines on the order as follows:
<td>
<%=(SOLines.Fields.Item("Description1").Value)%><br>
<%=(SOLines.Fields.Item("Description2").Value)%><br>
<%=(SOLines.Fields.Item("Description3").Value)%><br>
<%=(SOLines.Fields.Item("Description4").Value)%><br>
<%=(SOLines.Fields.Item("Description5").Value)%>
</td>
This is fine and works a treat, however more often than not only 2, 3 or 4 of the text fields will be used which will mean that my web page displays blank lines.
I was hoping to be able to write some code that would not display the line if it was null or contains no data, so after much digging I came up with the following:
<td>
<%=(SOLines.Fields.Item("Description1").Value)%><br>
<% if (SOLines.Fields.Item("Description2").Value != "") {(SOLines.Fields.Item("Description2").Value);}%><br>
<% if (SOLines.Fields.Item("Description2").Value != "") {(SOLines.Fields.Item("Description3").Value);}%><br>
<% if (SOLines.Fields.Item("Description2").Value != "") {(SOLines.Fields.Item("Description4").Value);}%><br>
<% if (SOLines.Fields.Item("Description2").Value != "") {(SOLines.Fields.Item("Description5").Value);}%><br>
</td>
Unfortunately for me this doesn't work and after several hours of trying different configurations of brackets, semi-colons other exciting stuff I'm still no closer to achieving my goal.
I have also tried using the Show region server behavior, but this only seems to apply to an entire recordset, not individual fields.
Is there a kind and helpful soul out there who can point out the error of my ways?
Many thanks in advance,
Dan
Copy link to clipboard
Copied
First, why are you using Javascript rather than VBScript? Next, you may have to test for null values, not the empty string. What exactly is occuring with the current code you posted?
Copy link to clipboard
Copied
Hi Bregent, thanks for the reply.
bregent wrote:
First, why are you using Javascript rather than VBScript?
Errr.... no idea. Thats what Dreamweaver has produced. Is it possible/acceptable/ethical to mix different coding languages in one page?
Since my original post I have modified the code so it now looks like this:
<td valign="top"><%=(SOLines.Fields.Item("Description1").Value)%>
<% if (SOLines.Fields.Item("Description2").Value != "") { %>
<br><%=(SOLines.Fields.Item("Description2").Value)%><br>
<% } %>
<% if (SOLines.Fields.Item("Description3").Value != "") { %>
<%=(SOLines.Fields.Item("Description3").Value)%><br>
<% } %>
<% if (SOLines.Fields.Item("Description4").Value != "") { %>
<%=(SOLines.Fields.Item("Description4").Value)%><br>
<% } %>
<% if (SOLines.Fields.Item("Description5").Value != "") { %>
<%=(SOLines.Fields.Item("Description5").Value)%><br>
<% } %>
</td>
This will produce a box containing 5 lines. Say for example that my text fields 1,2 and 3 contain some text while 4 and 5 are blank the following results:
| Description |
|---|
| Text line1 Text Line 2 Text Line 3 <blank line> <blank line> |
I have this morning tried checking for Null instead of "" as you suggested, and this seems to have solved my problem. So the code looks like this:
<td valign="top"><%=(SOLines.Fields.Item("Description1").Value)%>
<% if (SOLines.Fields.Item("Description2").Value != null) { %>
<br><%=(SOLines.Fields.Item("Description2").Value)%><br>
<% } %>
<% if (SOLines.Fields.Item("Description3").Value != null) { %>
<%=(SOLines.Fields.Item("Description3").Value)%><br>
<% } %>
<% if (SOLines.Fields.Item("Description4").Value != null) { %>
<%=(SOLines.Fields.Item("Description4").Value)%><br>
<% } %>
<% if (SOLines.Fields.Item("Description5").Value != null) { %>
<%=(SOLines.Fields.Item("Description5").Value)%><br>
<% } %>
</td>
This produces exactly what I want:
| Description |
|---|
| Text line1 Text Line 2 Text Line 3 |
Many thanks for posting.
I'm still interested to know what the advantages are of using VBScript though ![]()
Thanks again
Dan
.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now