[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Hide image control if no imageurl is returned from DB

Posted on 2007-11-25
3
Medium Priority
?
689 Views
Last Modified: 2013-11-06
Hello, I have used the following code in the past to hide an image control if the ImageURL is null but for some reason it is not working in this situation. Why can't this work?

I'm getting the following error on this line:
   If CType(Picture, String) Is DBNull.Value Then

Conversion from type 'DBNull' to type 'String' is not valid.


Markup:
<asp:Image ID="image" runat="server" ImageUrl= '<%# "~/EventGraphics/" & Eval("ImageURL") %>'
                    Visible='<%# CheckImage(Container.DataItem("ImageURL")) %>'/>


Function:

 Public Function CheckImage(ByVal Picture As Object) As Boolean

        If CType(Picture, String) Is DBNull.Value Then
            Return False
        Else
            Return True
        End If
    End Function
0
Comment
Question by:gogetsome
[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 Comments
 
LVL 14

Accepted Solution

by:
steveberzins earned 1500 total points
ID: 20348213
I think you want to use this:

 If Picture = DBNull.Value Then
        Return False
        Else
            Return True
        End If

not 100% sure, but think the problem is CType is going to make a string, and the compiler knows that there is not a string equivalent of DBNull.Value, so this will never be true. I've not done a lot of vb.net, but usually the Is keyword used for comparing types, not values, and usually used to do something like if x Is Nothing, or if x is String, not if x is String.Empty. maybe someone can explain this better, but I don't think 'Is' is ever really appropriate for value comparisons. (unless you happen to be a popular past president, then is has a whole different meaning :)
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20348494
<asp:Image ID="image" runat="server" ImageUrl= '<%# "~/EventGraphics/" & Eval("ImageURL") %>'
                    Visible='<%# CheckImage(Eval("ImageURL")) %>'/>



Public Function CheckImage(ByVal Picture As String) As String

        If  Picture <> "" Then
               
            Return  "True"
else
 Return  "False"

                   
        End If
    End Function
0
 

Author Comment

by:gogetsome
ID: 20350083
LOL, I must be a past president..

This did not work:
 If Picture = DBNull.Value Then
        Return False
        Else
            Return True
        End If

But this did:
 If Picture Is DBNull.Value Then
            Return False
        Else
            Return True
        End If

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

650 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