Hide field if its empty
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
