Results 1 to 4 of 4

Thread: only show field if data

  1. #1
    Join Date
    Feb 2005
    Posts
    153
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default only show field if data

    Hi, I have this piece of ASP code which displays data from the database

    Code:
    <tr><td>
    <strong>Organisation: <%= rstemp.Fields("Organisation").Value %></strong></td></tr>
    

    now I only want it to display this row (within the table) if there is data in the field.
    So I need a sort of 'if' statement to wrap around the table row.

    Im a ASP newbiw please be kind!

  2. #2
    Join Date
    Apr 2006
    Location
    Amsterdam
    Posts
    352
    Thanks
    20
    Thanked 11 Times in 11 Posts

    Default

    Something like this?

    Code:
    <%
    StrOrg = rstemp.Fields("Organisation").Value 
     
    If StrOrg <> "" then
    %>
    <tr><td>
    <strong>Organisation: <%= rstemp.Fields("Organisation").Value %></strong></td></tr>
    <%
    End If
    %>
    Just from the top of my mind, not tested the code.

  3. #3
    Join Date
    Jan 2006
    Posts
    419
    Thanks
    2
    Thanked 16 Times in 16 Posts

    Default

    Also test the code works when the value returned is null

  4. #4
    Join Date
    Feb 2004
    Posts
    4,903
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    Here is another way of doing it (note: its better performance wise to check the length of variables rather than compare it to an empty string).

    Code:
    <%
    Function CanShowField(ByRef Field)
        If Not IsNull(Field) Then
            If Not Len(Field) = 0 Then
                CanShowField = True
            End If
        End If
    End Function
    %>
    
    <% If CanShowField(rstemp("Organisation")) Then %>
    <tr><td><strong>Organisation: <%=rstemp("Organisation")%></strong></td></tr>
    <% End If %>
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. connecting to Data.SqlClient
    By mambojerry in forum ASP.NET
    Replies: 3
    Last Post: 25th January 2008, 07:11 AM
  2. Remote Data Access
    By Wise Webs in forum Technical Support
    Replies: 7
    Last Post: 28th November 2007, 12:45 PM
  3. Data Access Layer
    By creativeworks in forum ASP.NET
    Replies: 9
    Last Post: 30th March 2007, 12:33 PM
  4. PHP Data Object
    By nick in forum Community Feedback and Suggestions
    Replies: 5
    Last Post: 29th November 2006, 04:00 PM
  5. Replies: 1
    Last Post: 12th October 2006, 05:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •