Problem with if statement

Discussion in 'C#' started by Francis_htli, Dec 4, 2007.

  1. #1
    Below is the code that displays any field(s) that have values within the fieldset, but doesn't display any field(s) that don't have values.

    <FIELDSET><legend>Client Dinner/Entertainment</legend>
    <%if nullresult(rec("dwhat"))<>"" then%>
    What: <font color="#777777"><%=nullresult(rec("dwhat"))%></font><%end if%><br><br>
    <%if nullresult(rec("daudience"))<>"" then%>
    Audience: <font color="#777777"><%=nullresult(rec("daudience"))%></font><%end if%><br><br>
    <%if nullresult(rec("dwhen"))<>"" then%>
    Where: <font color="#777777"><%=nullresult(rec("dwhen"))%></font><%end if%><br><br>
    <%if nullresult(rec("dcontact"))<>"" then%>
    Contact: <font color="#777777">
    <%if instr(nullresult(rec("dcontact")), "@")>0 then%>
    <a href="mailto:<%=nullresult(rec("dcontact"))%>"><%=nullresult(rec("dcontact"))%></a>
    <%else%>
    <%=nullresult(rec("dcontact"))%>
    <%end if%>
    </font><%end if%>

    </FIELDSET>

    I want to add a code before the <fieldset> that it doesn't display anything within the fieldset if all four fields within the fieldset don't have values. The <%end if%> statement appears after </fieldset>. The code displays the fieldset if anyone of the fields have values.

    <%if nullresult(rec("dwhat"))<>"" | nullresult(rec("daudience"))<>"" | nullresult(rec("dwhen"))<>"" | nullresult(rec("dcontact"))<>"" then%>

    This code generates an error message "Character is not valid". What's wrong with the if statement at the top? Any other ways to make it work?
     
    Francis_htli, Dec 4, 2007 IP
  2. dementic

    dementic Peon

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    actually, you are testing for an empty string value
    nullresult(rec("dwhat"))<>""
    Code (markup):
    you should check for nulls, or change nulls to empty strings.

    e.g
    
    <%if IsNull(nullresult(rec("dwhat"))) | IsNull(nullresult(rec("daudience"))) | IsNull(nullresult(rec("dwhen"))) | IsNull(nullresult(rec("dcontact"))) then%> 
    
    Code (markup):
     
    dementic, Dec 4, 2007 IP