Is this the best or even right way to hide some text?

  • Thread starter Miguel Dias Moura
  • Start date
M

Miguel Dias Moura

Hello,

I want to display 6 database fields in this way:

{name}
{address}
Phone: {phone} | Fax: {fax}
URL: {url} | Email: {email}

Of course if {phone} field is empty I need to hide "Phone: {phone} | "

I came up with something like this (to hide the address line):

<table runat="server" visible='<%# users.FieldValue("address",
Container) <> "" %>'>
<tr>
<td><%# users.FieldValue("address", Container) %></td>
</tr>
</table>

It works but I am not convinced until now I wasn't able to display
everything as I want.

I also applied the same strategy to <spam> and <p> tags.
It's easier to set everything as I want but I am even less convinced.

Can I have some opinion about this?

I really would appreciate some help.

I am working in ASP.NET/VB.

Thanks,
Miguel
 
S

Scott M.

Why not just place the static text "Phone:" inside a label (lblPhone)
control and in your code-behind, simply write:

If IsDBNull(phoneField) then
lblPhone.visible = False
Else
lblPhone.visible = True
End If
 
M

Miguel Dias Moura

Hello,

Could you give me an example of application?
How do I implement that code?

Maybe this is a strange question but I work in Dreamweaver and sometimes
somethings get strange.

Can you give me a more complete example, even if simple one.

Thanks,
Miguel
 
S

Scott M.

You are doing .NET development in Dreamweaver? Dreamweaver isn't for .NET
development.

You create a Web Form label control in your .aspx page (<asp:Label
runat="server" ID="lblPhone" />).
You write the code I gave you earlier in whatever procedure or function that
is resposible for getting you your data.

That's all there is to it.
 
A

Alan Ferrandiz [MCT]

In that case for the structure you want to achieve if you are using a server-side table control the you can easily control the rows and cells that are added to the table. You could check if the field is empty and in that case do not add a cell to the row. It would be something like

Dim tr As TableRow
Dim tc As TableCell
tr = New TableRow
If # check if there is data present # Then
tc = New TableCell( # here goes your data # )
tr.Cells.Add(tc)
End If
Table1.Rows.Add(tr)

In that case if there is no telephone then the cell is simply not added to the row in the table.

Hope this helps

Alan Ferrandiz Langley [MCT]
geekswithblogs.com/aferrandiz
 
S

Scott M.

I think it is much simpler to just turn on/off the visibility of the label.
In that case for the structure you want to achieve if you are using a server-side table control the you can easily control the rows and cells that are added to the table. You could check if the field is empty and in that case do not add a cell to the row. It would be something like

Dim tr As TableRow
Dim tc As TableCell
tr = New TableRow
If # check if there is data present # Then
tc = New TableCell( # here goes your data # )
tr.Cells.Add(tc)
End If
Table1.Rows.Add(tr)

In that case if there is no telephone then the cell is simply not added to the row in the table.

Hope this helps

Alan Ferrandiz Langley [MCT]
geekswithblogs.com/aferrandiz
 
A

Alan Ferrandiz [MCT]

Yes, indeed It is much simpler to place the static text 'Phone' in a label. I tried your suggestion yesterday and it works excellent but i noticed that there is a blank space left when the data is not present so I came up with a solution consisting of building the table by adding rows in code so that if there is no data present i can modify the colspan attribute of the next cell so that it fits the whole row and no blank space is left.

Regarding the Dreamweaver topic, I prefer VS.NET for server side code development but I definitely think that VS.NET is not HTML friendly at all (at least until the 2003 version). I sometimes when editing some ..aspx pages use Dreamweaver and helps me a lot.

Alan Ferrandiz [MCT]
geekswithblogs.com/aferrandiz
Lima - Peru
"Scott M." <[email protected]> escribió en el mensaje I think it is much simpler to just turn on/off the visibility of the label.
In that case for the structure you want to achieve if you are using a server-side table control the you can easily control the rows and cells that are added to the table. You could check if the field is empty and in that case do not add a cell to the row. It would be something like

Dim tr As TableRow
Dim tc As TableCell
tr = New TableRow
If # check if there is data present # Then
tc = New TableCell( # here goes your data # )
tr.Cells.Add(tc)
End If
Table1.Rows.Add(tr)

In that case if there is no telephone then the cell is simply not added to the row in the table.

Hope this helps

Alan Ferrandiz Langley [MCT]
geekswithblogs.com/aferrandiz
 
M

Miguel Dias Moura

The solution I presented can also beapplied to <p> and <spam> tags.

It becomes really easier and simple to implement it.

Cheers,
Miguel

Alan Ferrandiz said:
Yes, indeed It is much simpler to place the static text 'Phone' in a
label. I tried your suggestion yesterday and it works excellent but i
noticed that there is a blank space left when the data is not present so I
came up with a solution consisting of building the table by adding rows in
code so that if there is no data present i can modify the colspan attribute
of the next cell so that it fits the whole row and no blank space is left.

Regarding the Dreamweaver topic, I prefer VS.NET for server side code
development but I definitely think that VS.NET is not HTML friendly at all
(at least until the 2003 version). I sometimes when editing some .aspx pages
use Dreamweaver and helps me a lot.

Alan Ferrandiz [MCT]
geekswithblogs.com/aferrandiz
Lima - Peru
"Scott M." <[email protected]> escribió en el mensaje
I think it is much simpler to just turn on/off the visibility of the
label.
In that case for the structure you want to achieve if you are using a
server-side table control the you can easily control the rows and cells that
are added to the table. You could check if the field is empty and in that
case do not add a cell to the row. It would be something like

Dim tr As TableRow
Dim tc As TableCell
tr = New TableRow
If # check if there is data present # Then
tc = New TableCell( # here goes your data # )
tr.Cells.Add(tc)
End If
Table1.Rows.Add(tr)

In that case if there is no telephone then the cell is simply not
added to the row in the table.

Hope this helps

Alan Ferrandiz Langley [MCT]
geekswithblogs.com/aferrandiz



Miguel Dias Moura said:
Hello,

I want to display 6 database fields in this way:

{name}
{address}
Phone: {phone} | Fax: {fax}
URL: {url} | Email: {email}

Of course if {phone} field is empty I need to hide "Phone: {phone} |
"

I came up with something like this (to hide the address line):

<table runat="server" visible='<%# users.FieldValue("address",
Container) <> "" %>'>
<tr>
<td><%# users.FieldValue("address", Container) %></td>
</tr>
</table>

It works but I am not convinced until now I wasn't able to display

everything as I want.

I also applied the same strategy to <spam> and <p> tags.
It's easier to set everything as I want but I am even less
convinced.

Can I have some opinion about this?

I really would appreciate some help.

I am working in ASP.NET/VB.

Thanks,
Miguel
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top