Link to home
Start Free TrialLog in
Avatar of gogetsome
gogetsomeFlag for United States of America

asked on

Hide image control if no imageurl is returned from DB

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
ASKER CERTIFIED SOLUTION
Avatar of steveberzins
steveberzins

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
Avatar of Pratima
<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
Avatar of gogetsome

ASKER

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