This topic is locked

PLEEEZE HELP! - How to hide a column if null?

6/27/2010 4:40:29 PM
ASPRunnerPro General questions
C
Conrunner author

Hello

I have a table which is laid out with 7 fields as shown (in horizontal layout)....

ID, G1, G2, G3, G4, G5, G6
Each user ID has only one row so that when one browses to the LIST page it would look like this for example...
ID, G1, G2, G3, G4, G5, G6

1, A, , C, D, E, F
As can be seen, for UserID 1 the value for G2 is blank, as it is NULL in the database. Rather than showing the above therefore I would like the asp page to completely hide or not display the G2 "column" if that is the correct terminology so that the following would be shown...
ID, G1, G3, G4, G5, G6

1, A, C, D, E, F
Then if G2 becomes not NULL, for example if it becomes B I would like this column again to be shown...
ID, G1, G2, G3, G4, G5, G6

1, A, B, C, D, E, F
What I have done to try and achieve this is to browse to visual editor and click in the G2 field, and then in the view as attribute add the custom code
Set xt = new XTempl

If IsNull(("G2")) Then

xt.assign ("G2"), false

Else

xt.assign ("G2"), true

End If
All that this does however is to hide the whole row of "column headers" (if that is the correct terminology) so that I get...
1, A, , C, D, E, F
with the empty field for G2 still shown - (and this happens whether G2 happens to be null or not!)
Could anybody possibly help me with this? I really would be extremely grateful, as this is driving me NUTS.
Thanks
Con.

A
ann 6/28/2010

Con,
use Before display event to hide the column. Here is a sample:

if Condition then

xt.assign "FieldName_fieldheadercolumn", false

end if



where FieldName is actual field name.

C
Conrunner author 6/28/2010



Con,
use Before display event to hide the column. Here is a sample:

if Condition then

xt.assign "FieldName_fieldheadercolumn", false

end if



where FieldName is actual field name.


Hi Ann

I am afraid this does not work. All that this does is hide the columnheader but not the rest of the column if I put
xt.assign "G2_fieldheadercolumn", false
However if I add in the condition
if IsNull(("G2")) then

xt.assign "G2_fieldheadercolumn", false

end if
then nothing happens at all!
Any other suggestions?
Con.

C
Conrunner author 6/28/2010

Hi

Me here again. This is really beginning to hurt now.

I have tried everything on the before display event but nothing works

I have put
if IsNull(("G2")) or IsEmpty ("G2") or ("G2")="" or len("G2")>0 then

xt.assign "G2_fieldheadercolumn",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. Please could somebody help? Do I need to add something else? The above code is everything that I have in the event.
Many Thanks

Con.

A
ann 6/29/2010

Con,
unfortunately, there is no reliable way to do it on the list page. Records can't be hided only if some values are null (otherwise the table structure will be broken). Also 'fieldcolumn' will hide all rows in the table, not just empty values.

C
Conrunner author 6/29/2010



Con,
unfortunately, there is no reliable way to do it on the list page. Records can't be hided only if some values are null (otherwise the table structure will be broken). Also 'fieldcolumn' will hide all rows in the table, not just empty values.


Hi Ann

Thanks for your reply but I don't think that I have adequately explained the situation. I understand what you say about table structure, but the fact of the matter is that this table, although it may contain several rows or records, only contains one row or record PER USER. So, when a user logs in they only see one row, and the value of G2 (the column I am trying to hide) is only one value, and this can only either be NULL or not. Additionally, the table I am testing this on only has one row. Additionally, what you have said regarding 'fieldcolumn' hiding all rows in the table would not appear to be correct; If I just put
xt.assign "G2_fieldheadercolumn",false

xt.assign "G2_fieldcolumn",false
in the BeforeDisplay event without an If condition, then only the G2 column and its header is hidden, which is just what I want. I need this however to be based on an If condition so that the column is only hidden if G2 is NULL. There seems to be a problem with the If condition however,
if IsNull(("G2")) or IsEmpty ("G2") or ("G2")="" or len("G2")>0 then

xt.assign "G2_fieldheadercolumn",false

xt.assign "G2_fieldcolumn",false

end if
because when I add this in the G2 column in not hidden anymore, irrespective of the value of G2 - NULL or not. It seems that although the G2 field is actually NULL, this is not meeting any of the If conditions I have listed in the syntax.
ALSO
I have tried
if ("G2")=NULL Then

Response.Write("This Field is Null")

Else

Response.Write("This Field is not Null")

End If
but the message is always "This Field is not Null" whether G2 is NULL or not. It seems to me that I am asking the wrong If condition, but I don't know which is the right one to ask.
Please can you help?
Con.

A
ann 6/30/2010

Con,
try this code to hide the header (Before Display event)

dim rsExists

set dal_table=dal.Table("TableName")

set rsExists = dal_table.Query("ISNULL(G2)","")

if not rsExists.eof then

xt.assign "G2_fieldheadercolumn",false

else

' if dont exist do something else
end if

rsExists.Close : set rsExists = Nothing



add this code to the After record processed event to hide row:

if isNull(data("G2")) then

record("G2_fieldcolumn")=false

end if



where TableName is your actual table name.