简体   繁体   中英

How to remove an <img> tag if no file path has been submitted from database

I have a repeater showing articles, where a picture can or cannot be submitted.

It works great, but when a picture is not inserted the alt text still shows, but no picture obviously.

<article class="newsPic">
           <img src="<%# Eval("picFilePath") %>" width="100%" alt="News Picture"/>
</article>

How can I remove the control if no file path has been submitted, if the field is null?

I have found this, but at present I can't see how to wrap an <img> tag around it?:

<asp:Label ID="MailingAddress" runat="server" 
   Text='<%# Eval("MailingAddress") %>' 
   Visible='<%# !string.IsNullOrEmpty(Eval("MailingAddress") as string) %>'/>

you just gave an answer to yourself :)

<img src='<%# Eval("picFilePath") %>' style="width:100%" alt="News Picture"
    runat="server" visible='<%# !string.IsNullOrEmpty(Eval("picFilePath") as string) %>' />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM