简体   繁体   English

如何在ASP.NET页面中使用服务器标签进行三元操作?

[英]How to make ternary operation with server tag in asp.net page?

I have a Repeater who contain an html link balise. 我有一个包含html链接栏的中继器。 I want both the attribute name and the text to be "..." if Eval("Name")==null or Eval("Name") instead. 如果Eval(“ Name”)== null或Eval(“ Name”)代替,我希望属性名称和文本均为“ ...”。 So I try to do this : 所以我尝试这样做:

<a runat="server" class="a_equipement" onserverclick="displayEquipment" name='<%= Eval("Nom")%> == null ? "..." : <%# Eval("Nom")%>'> <%= Eval("Nom");%> == null ? "..." : <%# Eval("Nom");%> </a>

But it didn't work and I got a weird error : "DC6_Configuration_Equipement.aspx(42,214): error CS1026: ) expected" 但是它没有用,并且出现了一个奇怪的错误:“ DC6_Configuration_Equipement.aspx(42,214):错误CS1026:)”

Is it possible to do it like this or are there other possibilities ? 是否有可能这样做或还有其他可能性?


After some research I try this : 经过一些研究,我尝试这样做:

name='<%# Eval("Nom") == null ? "..." : Eval("Nom")%>'

But same probleme again... I work on IE8, could it be compability issues ? 但是,同样的问题再次出现...我正在使用IE8,这可能是兼容性问题吗?

Thank's again for all your answer :) 再次感谢您的答复:)

Use it like this. 像这样使用它。 Then it will also work if Nom is "" : 如果Nom""它也将起作用:

<a runat="server" name='<%# string.IsNullOrEmpty(Eval("Nom").ToString()) ? "..." : Eval("Nom") %>'><%# string.IsNullOrEmpty(Eval("Nom").ToString()) ? "..." : Eval("Nom") %></a>

The compatibility with IE 8 has nothing to do with the ternary operator itself. 与IE 8的兼容性与三元运算符本身无关。

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

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