Solved

ASP.NET/VB: Only if not blank

Posted on 2011-09-06
6
238 Views
Last Modified: 2012-06-27
I use this VB ASP.NET code to display the publication title and content:
<p> 
<strong><%#Container.DataItem("PublicationTitle")%></strong><br />
<%#Container.DataItem("Content")%>
</p>

Open in new window


I only want the first line to be send if the publication title is NOT blank.  This does NOT work:

<p> 
[IF #Container.DataItem("PublicationTitle")]<strong><%#Container.DataItem("PublicationTitle")%></strong><br />[END-IF]
<%#Container.DataItem("Content")%>
</p>

Open in new window


0
Comment
Question by:hankknight
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 36490174
<p>
<% If Not String.IsNullOrEmpty(Container.DataItem("PublicationTitle")) Then
 Response.Write("<strong>" & Container.DataItem("PublicationTitle") & "</strong><br />")
 End If %>
<%#Container.DataItem("Content")%>
</p>
0
 
LVL 16

Author Comment

by:hankknight
ID: 36490245
That code gives me an error:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'Container' is not declared.

0
 
LVL 28

Expert Comment

by:strickdd
ID: 36490271
Sorry, my bad, I was thinking something else...

<p>
<%# GetTitleText(Container.DataItem("PublicationTitle")) %>
<%#Container.DataItem("Content")%>
</p>


public function GetTitleText(title As Object) As String
    If String.IsNullOrEmpty(title.ToString()) Then
       Return ""
    Else
       Return "<strong>" & title.ToString() & "</strong></br>"
    End If
end function
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 36490284
Hello, you have to use IIf(IsDBNull) function for that.
0
 
LVL 16

Author Comment

by:hankknight
ID: 36490371
I am still confused.  What code do I need to put where?
0
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 36490440
CODE IN-FRONT:
<p>
<%# GetTitleText(Container.DataItem("PublicationTitle")) %>
<%#Container.DataItem("Content")%>
</p>


CODE BEHIND
public function GetTitleText(title As Object) As String
    If String.IsNullOrEmpty(title.ToString()) Then
       Return ""
    Else
       Return "<strong>" & title.ToString() & "</strong></br>"
    End If
end function
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question