Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

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


Avatar of strickdd
strickdd
Flag of United States of America image

<p>
<% If Not String.IsNullOrEmpty(Container.DataItem("PublicationTitle")) Then
 Response.Write("<strong>" & Container.DataItem("PublicationTitle") & "</strong><br />")
 End If %>
<%#Container.DataItem("Content")%>
</p>
Avatar of hankknight

ASKER

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.

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
Avatar of SAMIR BHOGAYTA
Hello, you have to use IIf(IsDBNull) function for that.
I am still confused.  What code do I need to put where?
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial