Scott Scott -4 years ago 155
ASP.NET (C#) Question

asp repeater <img>

What I have is an asp repeater which brings through information for events that are created on the admin section of the web page.
These events are allowed to have images added onto them, I am able to bring the image through correctly, but what I am attempting to do is to bring through a generic image if no image is available.
What I have just now is:

<img id="eventlogoholder" visible="<%#If(Eval("event_logo").ToString > "", "True", "False")%>", title= "<%# Eval("event_title").ToString%>" alt="" src="<%# Replace(Eval("event_logo").ToString, Application("IMAGEFOLDER"), Application("IMAGETHUMBNAILS"))%>" />

So what this does is set the visible to false if no image is present else it will bring through the image.
So how could I modify the source so that it changes to:


if no image is present?



Answer Source

There is, on of them, solution based on comments:

Instead that Else replace it with , (period) ... If(condition, do if true, do if false)

src='<%#If(Eval("event_logo").ToString.Trim <> "", Replace(Eval("event_logo").ToString, Application("IMAGEFOLDER"), Application("IMAGETHUMBNAILS")) , "/Images/Thumbnailimages/posters/Noimage.jpg‌​")%>'

since You use eval You have to put all code inside ' instead ", src='**code**'

You have to use <> instead >, you dealing with string, not numbers.

I add Trim in Eval("event_logo").ToString.Trim ... there can be empty, space char and condition will be True

Of course, now You can remove complete code block for visible

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download