• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

ASP.NET/VB: Only if not blank

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
hankknight
Asked:
hankknight
  • 3
  • 2
1 Solution
 
strickddCommented:
<p>
<% If Not String.IsNullOrEmpty(Container.DataItem("PublicationTitle")) Then
 Response.Write("<strong>" & Container.DataItem("PublicationTitle") & "</strong><br />")
 End If %>
<%#Container.DataItem("Content")%>
</p>
0
 
hankknightAuthor Commented:
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
 
strickddCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello, you have to use IIf(IsDBNull) function for that.
0
 
hankknightAuthor Commented:
I am still confused.  What code do I need to put where?
0
 
strickddCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now