How to hide fields/columns which are null

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Conor
    New Member
    • Jun 2010
    • 5

    How to hide fields/columns which are null

    Hello. I am very bad at ASP and use ASPRunner Pro to write ASP pages for me. I have come across a problem however which I cannot figure out. Quite simply on a list page I have six fields, [G1 Title],[G2Title],[G3Title],[G4Title],[G5Title],[G6Title]. Depending on who has logged in however, not all of these fields will contain a value. Each of these has its own column and is only displayed once via a SELECT DISTINCT statement. In other words [G1 Title] for example is either populated or NULL, it can not be both. All that I want to do is get the ASP page not to show an empty column for [G1 Title] if it is null. I only want the columns for [G1 Title] through to [G6 Title] to display if their respective values are not NULL. Could anybody help me with this? I would be extremely grateful.
    Con.
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    show the code that (1)queries the db and (2)builds the table.

    Jared

    Comment

    • Conor
      New Member
      • Jun 2010
      • 5

      #3
      Originally posted by jhardman
      show the code that (1)queries the db and (2)builds the table.

      Jared
      Hi Jared

      As I have said I am very bad at ASP so I am not quite sure even what you mean.

      The code for the ASP Page is as follows...

      Code:
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <HTML {$html_attrs}><HEAD><TITLE>Test</TITLE>
      <link REL="stylesheet" href="include/style.css" type="text/css"><!--[if IE]><link REL="stylesheet" href="include/styleIE.css" type="text/css"><![endif]-->{BEGIN style_block}
      <STYLE>
      #height100{$id} {padding:10px;}
      #toplinks_caption{$id} {padding:0px 30px;font-size:12px;font-weight:bold;}
      #mastertable_block{$id} {margin-left:50px;margin-top:10px}
      #toplinks_block{$id} {width:100%;padding:3px;padding-left:30px}
      #toplinks_block{$id} span {padding-left:5px;}
      #search_records_block{$id} { padding-left:20px;}
      #search_records_block{$id} > * {vertical-align:middle;}
      #search_records_block{$id} select {margin:3px 0px;}
      #login_block{$id} {padding:10px; margin-bottom:3px}
      #login_block{$id} * {margin-left:5px; padding:5px 0px;}
      #menu_block{$id} {padding:10px;}
      #menu_block{$id} * {list-style-type:none;}
      #menu_block{$id} IMG {vertical-align:middle;}
      #records_block{$id} {margin-left:203px;}
      #record_controls{$id} {padding:10px 10px;}
      #record_controls{$id} span {padding-left:10px;}
      #recordcontrolsadd_block{$id} {padding:10px 10px;border: solid; border-width: 1px; border-color: #C0C0C0;}
      #recordcontrolsadd_block{$id} span {padding-left:10px;}
      #grid_block{$id} {border:solid 1px #C0C0C0;}
      .grid_recordheader{$id} {padding:0 5px 5px;vertical-align:top;}
      .grid_recordheader{$id} * {margin:0px 5px; vertical-align:top;}
      body {margin:0px;padding:0px;}
      </STYLE>
      {END style_block}
      <META name=GENERATOR content="MSHTML 8.00.7600.16588"></HEAD>
      <BODY {$bodyattrs} marginwidth="0" marginheight="0">{BEGIN body}
      <DIV id="height100{$id}">{$header} 
      {BEGIN toplinks_block}<DIV id="toplinks_block{$id}">&nbsp;<FONT 
      size=+0><B>Test</B></FONT> <SPAN id="login_block{$id}">Logged on 
      as&nbsp;<B>{$username}</B>&nbsp; <A 
      href="login.asp?a=logout">Log out</A> </SPAN>{BEGIN asearch_link}<SPAN><A 
      href="Test_search.asp">Advanced search</A></SPAN>{END asearch_link} </DIV>{END toplinks_block}
      <DIV id="recordcontrolsadd_block{$id}" class=shade>{BEGIN search_records_block}<SPAN id="search_records_block{$id}" class=shade>{BEGIN searchform}<SPAN id="searchform{$id}" class=shade><B>Search for: </B>&nbsp;&nbsp;&nbsp; {BEGIN searchform_field}<SELECT id="ctlSearchField{$id}"> <option value="">Any field</OPTION> <option value="ID" {$ID_searchfieldoption}>ID</OPTION> <option value="G1 Title" {$G1_Title_searchfieldoption}>G1 Title</OPTION> <option value="G2 Title" {$G2_Title_searchfieldoption}>G2 Title</OPTION> 
        <option value="G3 Title" {$G3_Title_searchfieldoption}>G3 Title</OPTION> <option value="G4 Title" {$G4_Title_searchfieldoption}>G4 Title</OPTION> <option value="G5 Title" {$G5_Title_searchfieldoption}>G5 Title</OPTION> <option value="G6 Title" {$G6_Title_searchfieldoption}>G6 Title</OPTION></SELECT>{END searchform_field} &nbsp; {BEGIN searchform_option}<SELECT id="ctlSearchOption{$id}"> <option value="Contains" {$Contains_searchtypeoption}>Contains</OPTION> <option value="Equals" {$Equals_searchtypeoption}>Equals</OPTION> <option value="Starts with ..." {$Starts_with_____searchtypeoption}>Starts with ...</OPTION> <option value="More than ..." {$More_than_____searchtypeoption}>More than ...</OPTION> <option value="Less than ..." {$Less_than_____searchtypeoption}>Less than ...</OPTION> 
        <option value="Equal or more than ..." {$Equal_or_more_than_____searchtypeoption}>Equal or more than ...</OPTION> 
        <option value="Equal or less than ..." {$Equal_or_less_than_____searchtypeoption}>Equal or less than ...</OPTION> 
        <option value="Empty" {$Empty_searchtypeoption}>Empty</OPTION></SELECT>{END searchform_option} &nbsp; {BEGIN searchform_text}<INPUT {$searchfor_attrs}>{END searchform_text} &nbsp; {BEGIN searchform_search}<INPUT class=button value=Search type=button {$searchbutton_attrs}>{END searchform_search} 
      &nbsp; {BEGIN searchform_showall}<INPUT class=button value="Show all" type=button {$showallbutton_attrs}>{END searchform_showall} 
      </SPAN>{END searchform}{BEGIN details_block}<SPAN>Details found: <B>{$records_found}</B>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>{END details_block} 
      {BEGIN pages_block}<SPAN>Page <B>{$page}</B> of <B>{$maxpages}</B></SPAN>{END pages_block} 
      &nbsp;&nbsp;&nbsp;&nbsp; {BEGIN recordspp_block}<SPAN id="recordspp_block{$id}">Records Per Page: <SELECT {$recordspp_attrs}> 
        <option value="10" {$rpp10_selected}>10</OPTION> <option value="20" {$rpp20_selected}>20</OPTION> <option value="30" {$rpp30_selected}>30</OPTION> <option value="50" {$rpp50_selected}>50</OPTION> <option value="100" {$rpp100_selected}>100</OPTION> <option value="500" {$rpp500_selected}>500</OPTION></SELECT> </SPAN>{END recordspp_block}</SPAN>{END search_records_block}</DIV>
      {BEGIN record_controls}<DIV id="record_controls{$id}"></DIV>{END record_controls}
      <DIV id="usermessage{$id}" class=message></DIV>
      {BEGIN grid_block}<TABLE style="WIDTH: 100%" id="grid_block{$id}" border=0 cellSpacing=2 cellPadding=3 name="maintable">
        <TBODY>
        {BEGIN grid_header}<TR vAlign=top {$gridHeader_attrs}>{BEGIN record_header}
          {BEGIN ID_fieldheadercolumn}<TD class=blackshade>{BEGIN ID_fieldheader}<A class=blackshade 
            {$ID_orderlinkattrs}>ID</A> {END ID_fieldheader}</TD>{END ID_fieldheadercolumn}
          {BEGIN G1_Title_fieldheadercolumn}<TD class=blackshade>{BEGIN G1_Title_fieldheader}<A class=blackshade 
            {$G1_Title_orderlinkattrs}>G1 Title</A> {END G1_Title_fieldheader}</TD>{END G1_Title_fieldheadercolumn}
          {BEGIN G2_Title_fieldheadercolumn}<TD class=blackshade>{BEGIN G2_Title_fieldheader}<A class=blackshade 
            {$G2_Title_orderlinkattrs}>G2 Title</A> {END G2_Title_fieldheader}</TD>{END G2_Title_fieldheadercolumn}
          {BEGIN G3_Title_fieldheadercolumn}<TD class=blackshade>{BEGIN G3_Title_fieldheader}<A class=blackshade 
            {$G3_Title_orderlinkattrs}>G3 Title</A> {END G3_Title_fieldheader}</TD>{END G3_Title_fieldheadercolumn}
          {BEGIN G4_Title_fieldheadercolumn}<TD class=blackshade>{BEGIN G4_Title_fieldheader}<A class=blackshade 
            {$G4_Title_orderlinkattrs}>G4 Title</A> {END G4_Title_fieldheader}</TD>{END G4_Title_fieldheadercolumn}
          {BEGIN G5_Title_fieldheadercolumn}<TD class=blackshade>{BEGIN G5_Title_fieldheader}<A class=blackshade 
            {$G5_Title_orderlinkattrs}>G5 Title</A> {END G5_Title_fieldheader}</TD>{END G5_Title_fieldheadercolumn}
          {BEGIN G6_Title_fieldheadercolumn}<TD class=blackshade>{BEGIN G6_Title_fieldheader}<A class=blackshade 
            {$G6_Title_orderlinkattrs}>G6 Title</A> {END G6_Title_fieldheader}</TD>{END G6_Title_fieldheadercolumn}{END record_header}</TR>{END grid_header}
        {BEGIN grid_row}<TR vAlign=top {$rowattrs} {$rowstyle}>{BEGIN grid_record}
          {BEGIN ID_fieldcolumn}<TD vAlign=middle align=left {$ID_style}>{$ID_value} </TD>{END ID_fieldcolumn}
          {BEGIN G1_Title_fieldcolumn}<TD vAlign=middle align=left {$G1_Title_style}>{$G1_Title_value} </TD>{END G1_Title_fieldcolumn}
          {BEGIN G2_Title_fieldcolumn}<TD vAlign=middle align=left {$G2_Title_style}>{$G2_Title_value} </TD>{END G2_Title_fieldcolumn}
          {BEGIN G3_Title_fieldcolumn}<TD vAlign=middle align=left {$G3_Title_style}>{$G3_Title_value} </TD>{END G3_Title_fieldcolumn}
          {BEGIN G4_Title_fieldcolumn}<TD vAlign=middle align=left {$G4_Title_style}>{$G4_Title_value} </TD>{END G4_Title_fieldcolumn}
          {BEGIN G5_Title_fieldcolumn}<TD vAlign=middle align=left {$G5_Title_style}>{$G5_Title_value} </TD>{END G5_Title_fieldcolumn}
          {BEGIN G6_Title_fieldcolumn}<TD vAlign=middle align=left {$G6_Title_style}>{$G6_Title_value} </TD>{END G6_Title_fieldcolumn}{END grid_record}</TR>{END grid_row}</TBODY></TABLE>{END grid_block}
      {BEGIN pagination_block}<DIV class=toplist align=center>{$pagination}</DIV>{END pagination_block}
      {BEGIN message_block}<DIV class=toplist align=center valign="middle"><B>{$message}</B></DIV>{END message_block}{$footer} </DIV>{END body}</BODY></HTML>

      The query is just SELECT * FROM Test but I'm not sure if that's what you mean by the code that queries the db.

      Many Thanks

      Con
      Last edited by Niheel; Jun 22 '10, 05:21 PM. Reason: please use code tags to post code

      Comment

      • Conor
        New Member
        • Jun 2010
        • 5

        #4
        Originally posted by jhardman
        show the code that (1)queries the db and (2)builds the table.

        Jared
        Hi Jared
        I just wondered if you had had any thoughts on this? It is giving me a real headache.
        Thanks
        Con

        Comment

        • viktorka
          New Member
          • Jun 2010
          • 26

          #5
          Why don't you try using isnull function.
          Example

          strValue = ""
          if not isnull(rst.fiel d("Column1")) then strValue = rst.field("Colu mn1")

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            I don't recognize the code at all, it doesn't look like asp to me. What development environment are you using?

            Jared

            Comment

            • Conor
              New Member
              • Jun 2010
              • 5

              #7
              Originally posted by jhardman
              I don't recognize the code at all, it doesn't look like asp to me. What development environment are you using?

              Jared
              Hi Jared
              It is ASPRunner Pro. So far I have come up with...

              if IsNull(("G2")) or IsEmpty ("G2") or ("G2")="" or len("G2")>0 then
              xt.assign "G2_fieldheader column",false
              xt.assign "G2_fieldcolumn ",false
              end if

              but this just gets rid of the G2 header and its column whether the value for G2 is null or not. It is as if none of the above if conditions actually mean a NULL value in the database.

              Con.

              Comment

              • viktorka
                New Member
                • Jun 2010
                • 26

                #8
                Originally posted by jhardman
                I don't recognize the code at all, it doesn't look like asp to me. What development environment are you using?

                Jared
                This is classic ASP.
                isnull is a function (VBscript and Visual Basic the same) that verifies a variable/field for a NULL

                Comment

                • Conor
                  New Member
                  • Jun 2010
                  • 5

                  #9
                  Originally posted by viktorka
                  This is classic ASP.
                  isnull is a function (VBscript and Visual Basic the same) that verifies a variable/field for a NULL
                  Yes but how do I use it?
                  Con.

                  Comment

                  • jhardman
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3405

                    #10
                    Originally posted by viktorka
                    This is classic ASP.
                    isnull is a function (VBscript and Visual Basic the same) that verifies a variable/field for a NULL
                    no, I recognize isnull, that's fine, what I don't recognize is
                    Code:
                    #    {BEGIN G1_Title_fieldheadercolumn}<TD class=blackshade>{BEGIN G1_Title_fieldheader}<A class=blackshade 
                    #       {$G1_Title_orderlinkattrs}>G1 Title</A> {END G1_Title_fieldheader}</TD>{END G1_Title_fieldheadercolumn}
                    This does not look like ASP classic, or ASP.NET. I guess it could just be place-holders for a wysiwyg editor, but this doesn't show how you are connecting to the db.

                    In asp this code usually looks something like this:
                    Code:
                    dim objConn, objRS, strQuery
                    set objConn = server.createobject("adodb.connection")
                    objConn.open "DSN=myDSN;UID=myUser;pwd=myPwd"
                    set objRS = server.createobject("adodb.recordset")
                    strQuery = "SELECT * FROM myTable"
                    objRS.open strQuery, objConn
                    This is the code I'm looking for that queries the db. The code that builds the table is going to look something like this:
                    Code:
                    <table><tr>
                    <%
                    for each x in objRS.fields
                       response.write "<th>" & x & "</th>" & vbNewLine
                    next %>
                    </tr>
                    <%
                    do until objRS.eof
                       response.write "<tr>"
                       for each x in objRS.fields
                          response.write "<td>" & objRS(x) & "</td>" & vbNewLine
                       next
                       response.write "</tr>"
                       objRS.moveNext
                    loop %>
                    </table>
                    Jared

                    Comment

                    Working...