Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET/VB: Only if not blank

Posted on 2011-09-06
6
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 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