简体   繁体   English

检查Eval()是否为零,并显示锚标记的状态

[英]check if Eval() is zero and condition display of anchor tag

i have a repeater. 我有一个中继器。 and it fill certain numeric values within anchor tag. 并将其填充到锚标记中的某些数值。 but if the value is zero i just want to display a span and anchor is discarded. 但是如果该值为零,我只想显示一个跨度,而锚点将被丢弃。

this is my code. 这是我的代码。

in HTML 在HTML中

    <td>
        <%if (ProcessMyDataItem(Eval("7DAYS").ToString()))
         {%>
<a class='aDetails' href="DashCheckInCheckOutDetails.aspx?building=<%=hiddenBuildingDetailsId.Value.ToString() %>&action=<%#Eval("ID") %>&day=7&name=<%#Eval("DESC") %>"><%#Eval("7DAYS") %> </a>
     <% }
      else
      {
          Response.Write("<span>0</span>");
      }
      %>
     </td>

and in the codebehind i have 在后面的代码中

public bool ProcessMyDataItem(string myValue)
        {
            if (myValue == "0")
            {
                return false;
            }

            return true;
        }

but when i run it, shows an error 但是当我运行它时,显示错误

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. 诸如Eval(),XPath()和Bind()之类的数据绑定方法只能在数据绑定控件的上下文中使用。

is there any way to check eval value is zero and if zero, display span, else display anchor tag. 有什么方法可以检查评估值是否为零,如果为零,则显示跨度,否则显示锚标记。

Try using: 尝试使用:

 <%#Eval("7DAYS").ToString() != "0" ?"<a class='aDetails' href='DashCheckInCheckOutDetails.aspx?...'>3 </a>":" <span>0</span>"%>

This will work! 这将起作用! i have tested! 我已经测试过!

NOTE: please add the url for the link as per your need. 注意:请根据需要添加链接的url

Updated Answer: 更新的答案:

  <%#Eval("7DAYS").ToString() != "0" ? "<a class='aDetails' href=DashCheckInCheckOutDetails.aspx?building="+hiddenBuildingDetailsId.Value+"&action="+Eval("ID") +"&day=7&name="+Eval("DESC") +">"+Eval("7DAYS")+" </a>" : " <span>0</span>" %>

This will work. 这将起作用。

This is what I think 这就是我的想法

<%# Eval("7DAYS") == 0 ? "empty" : "notempty" %>

Also if the field value type is supposed to be string you could do something along the lines of.. 另外,如果应该将字段值类型设置为字符串,则可以按照以下方法进行操作。

<%# (Eval("7DAYS") as string) ?? "empty" %>

You must change your 'a tag' like this, 您必须像这样更改“标签”,

<a class="aDetails" href="DashCheckInCheckOutDetails.aspx?building="+<%hiddenBuildingDetailsId.Value.ToString() %>&action=<%Eval("ID") %>&day=7&name=<%Eval("DESC") %>'><% Eval("7DAYS") %> </a>

Let me know the result. 让我知道结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM