gogetsome
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.DataI tem("Image URL")) %>'/>
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
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.DataI
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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