【问题标题】:If statement on aspx [duplicate]如果关于aspx的声明[重复]
【发布时间】:2013-11-23 12:06:59
【问题描述】:

asp.net 新手...

DataListItemTemplate,我想检查数据库中的value ("Exchange")是否为真。

如果是真的,我想显示一个带有文本“True”的标签。

请注意,Exchange 在数据库中存储为

正在考虑这个,但还没有成功。

 <%#Eval("Exchange").ToString() == "True" ? "<asp:Label ID=\"Exchange\" runat=\"server\" Text=\"True">   </asp:Label>":""%>

谁能帮忙?

非常感谢

【问题讨论】:

标签: asp.net gridview eval


【解决方案1】:

asp.net 做你想做的事情的方式是这样的。

<asp:Label ID="Exchange" runat="server" Text="True" Visible='<%# Eval("Exchange").ToString() == "True" %>' />

如果Exchange 是布尔值,则不需要ToString 调用

<asp:Label ID="Exchange" runat="server" Text="True" Visible='<%# Eval("Exchange") %>' />

【讨论】:

    【解决方案2】:

    我无法尝试,但您可以为 text 属性编写 if。如果 Eval("Exchange") 返回的不是 "True"

    <asp:Label ID="Exchange" runat="server" Text='<%# Eval("Exchange")=="True" ? "True": "" %></asp:Label>'
    

    【讨论】:

      【解决方案3】:

      DataReader["Exchange"].ToString() 本身将返回一个字符串"True""False",因此您不需要为此使用任何条件:

          <asp:Label ID=\"Exchange\" runat=\"server\" Text=\"<%#Eval("Exchange").ToString()%>\" </asp:Label>
      

      【讨论】:

        猜你喜欢
        • 2013-11-13
        • 1970-01-01
        • 2014-03-15
        • 1970-01-01
        • 1970-01-01
        • 2012-10-24
        • 1970-01-01
        • 1970-01-01
        • 2016-10-22
        相关资源
        最近更新 更多