Reputation: 80
I am trying to create an If that has the condition that, if the eval value is 0 the div wont appear.
<%@ if (DataBinder.Eval(Container.DataItem, "Desconto").ToString() != "0"){ %>
<p><span class="oldprice"><%# Eval("Preço") %>€</span> <i class="newprice item_price"><%# ((decimal)Eval("Preço")-(decimal)Eval("Preço")*((decimal)(int)Eval("Desconto")/100)).ToString("N2") %></i>€</p>
<%@ } %>
But i am not figuring out the syntax to create the eval, it aways ends up as some error.
Thanks in advance for reply.
Upvotes: 1
Views: 173
Reputation: 84
Use # instead of @ -
<%# if (DataBinder.Eval(Container.DataItem, "Desconto").ToString() != "0"){ %>
<p><span class="oldprice"><%# Eval("Preço") %>€</span> <i class="newprice item_price"><%# ((decimal)Eval("Preço")-(decimal)Eval("Preço")*((decimal)(int)Eval("Desconto")/100)).ToString("N2") %></i>€</p>
<% } %>
Upvotes: 1
Reputation: 35514
You can wrap the code inside a Panel
and set the Visible
based on the value of the Eval.
<asp:Panel ID="Panel1" runat="server" Visible='<%# Eval("Desconto").ToString() != "0" %>'>
content
</asp:Panel>
Or use a ternary operator if you do not want an extra Panel
<div style="display:<%# Eval("Desconto").ToString() != "0" ? "block" : "none" %>">
content
</div>
Upvotes: 1