Conditionally display image within FormView

M

Mike

I'm using a SqlDataSource to fetch data and display it in a FormView. One
of the elements is an image:

<asp:Image ID="ImageFile" runat="server" ImageURL='<%# Eval("ImageFile",
"~/storyimages/{0}") %>' />

However, sometimes there is no image to display, and therefore I want to set
the Image control's Visible property to false. I tried evaluating whether
the ImageFile field has a vlaue or not and using it to set the Visible
property like so:
Visible='<%# Eval("ImageFile") != DBNull.Value %>'

Nor does Visible='<%# Eval("ImageFile").ToString()!=null%>'

Can anyone point me ion the right direction?

Thanks
 
M

Mike

Mike said:
I'm using a SqlDataSource to fetch data and display it in a FormView. One
of the elements is an image:

<asp:Image ID="ImageFile" runat="server" ImageURL='<%# Eval("ImageFile",
"~/storyimages/{0}") %>' />

However, sometimes there is no image to display, and therefore I want to
set the Image control's Visible property to false. I tried evaluating
whether the ImageFile field has a vlaue or not and using it to set the
Visible property like so:
Visible='<%# Eval("ImageFile") != DBNull.Value %>'

Nor does Visible='<%# Eval("ImageFile").ToString()!=null%>'

Ignore this. I discovered my empty database fields were not nulls. They
contained empty strings. I updated the db, and now the above works fine.

Doh.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top