【发布时间】:2020-04-05 11:37:28
【问题描述】:
我正在尝试使用 Eval 条件在 aspx 页面中使用 if else 条件。但它在else 条件和) 在if 条件下显示错误红线。
代码
<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>
<% } %>
【问题讨论】:
-
我无法测试您的代码,但我知道您应该使用 ForExample:
1 + 2 =<%= (1+2).ToString() %>那么此代码可能有效。<% if (string.IsNullOrEmpty(Eval("PromoPrice", "{0:,00}").ToString())) { %>或<% if (string.IsNullOrEmpty(<%# Eval("PromoPrice", "{0:,00}").ToString()) %>) { %> -
嗨@SoheilaTarighi 感谢您的回复,我尝试但现在它显示此错误消息
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. -
这能回答你的问题吗? stackoverflow.com/questions/2571545/…
-
感谢我的问题解决了....我尝试了可见属性