【问题标题】:How to use IF ELSE using EVAL condition in aspx c#如何在aspx c#中使用EVAL条件使用IF ELSE
【发布时间】: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 =&lt;%= (1+2).ToString() %&gt; 那么此代码可能有效。&lt;% if (string.IsNullOrEmpty(Eval("PromoPrice", "{0:,00}").ToString())) { %&gt;&lt;% if (string.IsNullOrEmpty(&lt;%# Eval("PromoPrice", "{0:,00}").ToString()) %&gt;) { %&gt;
  • 嗨@SoheilaTarighi 感谢您的回复,我尝试但现在它显示此错误消息Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
  • 这能回答你的问题吗? stackoverflow.com/questions/2571545/…
  • 感谢我的问题解决了....我尝试了可见属性

标签: c# asp.net eval


【解决方案1】:

您可以使用如下所示的方法:

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

【讨论】:

    猜你喜欢
    • 2013-06-08
    • 2019-04-25
    • 1970-01-01
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多