0

I am trying to use if else conditions in aspx page using Eval conditions. But its showing error red line in else condition and in ) in if condition.

Code

<div class="price_mth text-center">
<% if (string.IsNullOrEmpty(Eval("PromoPrice", "{0:,00}").ToString()) %>) { %>
<asp:panel id="pricePanel" runat="server" >
<h2><i class="fa fa-usd" aria-hidden="true"></i> <%# Eval("Price", "{0:,00}") %><sup>.00/mo</sup></h2>
</asp:panel>
 <% } %>

<% else { %>                                              
<asp:panel id="promopanel" runat="server">
<div class="style-1">
 <h2> <del><i class="fa fa-usd" aria-hidden="true"></i> <span class="amount"><%# Eval("Price", "{0:,00}") %></span> </del><sup>.00/mo</sup></h2>
 <h2><ins><i class="fa fa-usd" aria-hidden="true"></i> <span class="amount"><%# Eval("PromoPrice", "{0:,00}") %></span></ins><sup>.00/mo</sup></h2>
</div>
 </asp:panel>
<% } %>

don
  • 65
  • 2
  • 10
  • I can't test your code but I know you should use ForExample:`1 + 2 =<%= (1+2).ToString() %>` then this code maybe work.`<% if (string.IsNullOrEmpty(Eval("PromoPrice", "{0:,00}").ToString())) { %>` or `<% if (string.IsNullOrEmpty(<%# Eval("PromoPrice", "{0:,00}").ToString()) %>) { %>` – Soheila Tarighi Apr 05 '20 at 11:52
  • Hi @SoheilaTarighi thanks for response, i try but now its showing this error message `Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.` – don Apr 05 '20 at 11:56
  • does this answer your question? https://stackoverflow.com/questions/2571545/databinding-methods-such-as-eval-xpath-and-bind-can-only-be-used-in-the – Soheila Tarighi Apr 05 '20 at 11:58
  • Thanks my issue resolved.... i have try visible property – don Apr 05 '20 at 12:12

1 Answers1

0

You can use a method as shown below:

<asp:Panel ID="p1" Visible='<%# BLL.Logic.ShowPanel(Eval("PromoPrice", "{0:,00}")) %>' runat="server">   
</asp:Panel>
Jacknife
  • 35
  • 1
  • 1
  • 10