在Repeater控件三元内嵌ASP.NET [英] Ternary inline ASP.NET in Repeater control

查看:105
本文介绍了在Repeater控件三元内嵌ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我在的ItemTemplate 中继的名为readMore链接按钮,我想设置显示:无; 它,当每个岗位的含量小于说,2000个字符。

Imagine that I have a link button called "readMore" in the ItemTemplate of a repeater, and I want to set display: none; for it, when the content of each post is less than say, 2000 characters.

<asp:repeater id="postsRepeater" runat="server" 
  onitemdatabound="postsRepeater_ItemDataBound">
    <ItemTemplate>
            <a class="button" href="#" runat='server' id='more'>Read More</a>
    </ItemTemplate>
</asp:repeater>

在PHP中,你可以简单地写类似:

In PHP, you can simply write something like:

<?php echo (contentLength < 2000 ? 'display: none;' : ''); ?>

不过,我测试code和它trowed和错误:

However, I tested this code and it trowed and error:

<%= Eval("Content").Length < 2000 ? "display: none;" : string.Empty %>

是否有可能写的三元内嵌在ASP.NET Repeater控件?怎么样?

Is it possible to write ternary inline ASP.NET in a Repeater control? How?

推荐答案

这不是三元运算符的问题;这是数据绑定的问题控件,因为你必须使用而不是 =

It is not an issue of ternary operator; it is an issue of Databound controls because you have to use # instead of =.

使用此

<%# Eval("Content").ToString().Length < 2000 ? "display: none;" : string.Empty %>

而不是

<%= Eval("Content").ToString().Length < 2000 ? "display: none;" : string.Empty %>

这篇关于在Repeater控件三元内嵌ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆