Make Address Look Better

P

pvong

VB.Net

I'm pulling Data from a DB and creating a letter by filling the Labels. It
works perfectly, but if Addr2 and Addr3 are blank, it leaves a Blank space
in that area. Is there a way to make it so I can say if the data is empty,
temporarely delete the label or make it not exist at all? I'm not talking
about just hiding it because it still leaves an empy space.

This is what I get:
FirstName LastName
Addr1
Addr2 (this is blank if no data)
Addr3 (this is blank if no data)
City, State ZIP

This is what I want to get if Addr2 & Addr3 are blank:
FirstName LastName
Addr1
City, State ZIP

Here is my Code:
If Not dr.Item("CustodianAddress2").ToString = String.Empty Then

CustAddr2L.Text = dr.Item("CustodianAddress2")

End If

If Not dr.Item("CustodianAddress3").ToString = String.Empty Then

CustAddr3L.Text = dr.Item("CustodianAddress3")

End If
 
I

IfThenElse

Don't use CustAddr2L and CustAddr3L Just add everything to CustAddr1L
if CustAddr2L and CustAddr3L exit then add then to CustAddr1L
This way you don't need to remove anything.
 
P

pvong

What do I put in there so it will include a <BR> to it's not all on the same
line? This is my new code and they all run together. I know how to put 1
space in between, but how do you put a return character?
CustAddr1L.Text = dr.Item("CustodianAddress1") &
dr.Item("CustodianAddress2") & dr.Item("CustodianAddress3")
 
P

pvong

I'm using WebForm if that matters.


IfThenElse said:
Don't use CustAddr2L and CustAddr3L Just add everything to CustAddr1L
if CustAddr2L and CustAddr3L exit then add then to CustAddr1L
This way you don't need to remove anything.
 
A

Alexey Smirnov

What do I put in there so it will include a <BR> to it's not all on the same
line? This is my new code and they all run together. I know how to put 1
space in between, but how do you put a return character?
CustAddr1L.Text = dr.Item("CustodianAddress1") &
dr.Item("CustodianAddress2") & dr.Item("CustodianAddress3")







- Show quoted text -

if blank means null

CustAddr1L.Text = dr.Item("CustodianAddress1") _
& IsDBNull(dr.Item("CustodianAddress2"), "", "<br>" &
dr.Item("CustodianAddress2"))
& IsDBNull(dr.Item("CustodianAddress3"), "", "<br>" &
dr.Item("CustodianAddress3"))
 
S

Scott M.

Just put asp:Label controls on the WebForm where you will want the
appropriate content to go (using a table for presice layout is a great
idea). Then just pull out the data from your DataReader and put it into the
appropriate label. No need to fuss with <BR> at all.
 
S

Scott M.

See my reply to pvong. Adding HTML <BR> tags is sooooo Classic ASP. Use
labels instead.
 
P

pvong

Scott, that's my problem to begin with. I do have labels and all the data
are flowing correctly, but it leaves a blank space where the Label is for
Address2 and 3 which is what I'm trying to avoid.

Can you take my code and show me how you would do it with multiple labels?
 
A

Alexey Smirnov

Scott, that's my problem to begin with. I do have labels and all the data
are flowing correctly, but it leaves a blank space where the Label is for
Address2 and 3 which is what I'm trying to avoid.

Can you take my code and show me how you would do it with multiple labels?

The only thing you can do is to make an "empty" label invsible when it
has no text. It would help to make no empty line.
 
P

pvong

I tried your code:

CustAddr1L.Text = dr.Item("CustodianAddress1") &
IsDBNull(dr.Item("CustodianAddress2"), "", "
" & dr.Item("CustodianAddress2")) & IsDBNull(dr.Item("CustodianAddress3"),
"", "
" & dr.Item("CustodianAddress3"))

But I get the error message of:
Too Many Arguments to Public Funcion 'ISDBNULL(Expression As Object) As
Boolean'.
 
S

Scott M.

Just add if..then logic to hide the label if there is no data for it.

[psuedo code]

label2.visible = false
If Not IsDBNull(dr("itemName")) Then
label2.visible = true
label2.text = dr("itemName")
End If
 
A

Alexey Smirnov

I tried your code:

CustAddr1L.Text = dr.Item("CustodianAddress1") &
IsDBNull(dr.Item("CustodianAddress2"), "", "
" & dr.Item("CustodianAddress2")) & IsDBNull(dr.Item("CustodianAddress3"),
"", "
" & dr.Item("CustodianAddress3"))

But I get the error message of:
Too Many Arguments to Public Funcion 'ISDBNULL(Expression As Object) As
Boolean'.

Sorry, I forgot about IIF

CustAddr1L.Text = dr.Item("CustodianAddress1") _
& Iif(IsDBNull(dr.Item("CustodianAddress2"), "", "<br>" &
dr.Item("CustodianAddress2")) _
& Iif(IsDBNull(dr.Item("CustodianAddress3"), "", "<br>" &
dr.Item("CustodianAddress3"))

The idea is just to check the value and if it equals to NULL return an
empty string.

It is an equivalent to

CustAddr1L.Text = dr.Item("CustodianAddress1")

If IsDBNull(dr.Item("CustodianAddress2") Then
CustAddr1L.Text &= ""
Else
CustAddr1L.Text &= "<br>" & dr.Item("CustodianAddress2"))
End If

If IsDBNull(dr.Item("CustodianAddress3") Then
CustAddr1L.Text &= ""
Else
CustAddr1L.Text &= "<br>" & dr.Item("CustodianAddress3"))
End If

or

CustAddr1L.Text = dr.Item("CustodianAddress1")

If Not IsDBNull(dr.Item("CustodianAddress2") Then CustAddr1L.Text &=
"<br>" & dr.Item("CustodianAddress2"))
If Not IsDBNull(dr.Item("CustodianAddress3") Then CustAddr1L.Text &=
"<br>" & dr.Item("CustodianAddress3"))

http://msdn2.microsoft.com/en-us/library/27ydhh0d(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/tckcces5(VS.80).aspx
 
A

Alexey Smirnov

Sorry, I forgot about IIF

CustAddr1L.Text = dr.Item("CustodianAddress1") _
& Iif(IsDBNull(dr.Item("CustodianAddress2"), "", "<br>" &
dr.Item("CustodianAddress2")) _
& Iif(IsDBNull(dr.Item("CustodianAddress3"), "", "<br>" &
dr.Item("CustodianAddress3"))

CustAddr1L.Text = dr.Item("CustodianAddress1") _
& Iif( IsDBNull(dr.Item("CustodianAddress2")) , "", "<br>" &
dr.Item("CustodianAddress2") ) _
& Iif( IsDBNull(dr.Item("CustodianAddress3")), "", "<br>" &
dr.Item("CustodianAddress3") )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top