在我的.aspx中我正在寻找基于来自绑定的值添加If语句。我试过以下内容:ASP.NET在.aspx中使用Bind/Eval if语句
<% if(bool.Parse(Eval("IsLinkable") as string)){ %>
monkeys!!!!!!
(please be aware there will be no monkeys,
this is only for humour purposes)
<%} %>
IsLinkable是一个来自Binder的布尔。我收到以下错误:
InvalidOperationException
Databinding methods such as Eval(), XPath(), and Bind() can only
be used in the context of a databound control.
我认为问题是他将语句嵌入到期望表达式的东西中。 – asawyer 2011-04-08 14:44:55
@asawyer听起来对我来说是一个很好的解释。我没有真正想过这种方式,但它非常有意义。 – Bazzz 2011-04-10 14:29:35
这也适用于中继器控制。 – Bern 2013-11-22 15:42:53