Reputation: 7555
I have ASP.Net(aspx) where I need to render the html based on some condition. This is how my aspx looks like.
<%# Eval("FileName").ToString() == "pdf" ?"True":"False"%>
This is returning string True or False based on the condition however I need to render the html as below.
<%# Eval("FileName").ToString() == "pdf" ?"":"<img src='<%# DataBinder.Eval(Container.DataItem, 'FilePathUrl')%>' />"%>
How do I address this?
Upvotes: 2
Views: 60
Reputation: 1
You can use "if" statement instead of "?:"
<% if (Eval("FileName").ToString() != "pdf")%>
<% { %>
<img src='<%# DataBinder.Eval(Container.DataItem, 'FilePathUrl')%>
<% } %>
Upvotes: 0
Reputation: 35514
You need to create the string for the image like this:
<%# Eval("FileName").ToString() == "pdf" ? "" : "<img src=\"" + Eval("FilePathUrl").ToString() + "\">" %>
You cannot nest databinding expressions like you are doing.
Upvotes: 3