Solved

ASP.NET/VB: Only if not blank

Posted on 2011-09-06
6
233 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now