虽然关于这个主题有几个问题,但我还没有找到任何令人满意的答案。
我有一台需要显示复杂内容的中继器。模板中需要IF
语句。我无法将其移至代码隐藏,因为我需要在转发器中注册服务器控件和用户控件。这就是我需要的:
<asp:Repeater ID="rCom" runat="server" ClientIDMode="Static">
<ItemTemplate>
<%# If CBool(Eval("IsFix")) Then%>
<%-- HTML content including server and user controls --%>
<%Else%>
<%-- HTML content including server and user controls --%>
<%End If%>
</ItemTemplate>
</asp:Repeater>
以上引发编译错误。有关如何实现这一点的任何想法?我需要评估IsFix
语句中的If
字段。
答案 0 :(得分:4)
我会将每组内容放在服务器端面板中,然后在ItemDataBound事件上,将一个面板的可见性设置为true,另一个面板的可见性设置为false。 如果在服务器端设置了可见性,则前端内容甚至不会被渲染。
答案 1 :(得分:2)
从具有#
语句的代码块中删除if
: -
<asp:Repeater ID="rCom" runat="server" ClientIDMode="Static">
<ItemTemplate>
<% CBool(Eval("IsFix")) Then%>
<%-- HTML content including server and user controls --%>
<%Else%>
<%-- HTML content including server and user controls --%>
<%End If%>
</ItemTemplate>
</asp:Repeater>
修改强>
尝试使用条件运算符(我不确定VB.NET中的语法,请检查): -
<%# If(CBool(Eval("IsFix")), "Do Something", "Else do something" %>
答案 2 :(得分:1)
完美无缺!!
<%# If(CBool(Eval("bitExtemporaneo")) = True, "<img src=""Imagenes/Extempo.png"" alt=""Extemporaneo""/>", "")%>
答案 3 :(得分:0)
从包含if语句的代码中删除#。
然后使用这样的代码。
<%
object objIsFix = ((System.Data.DataTable)rep.DataSource).Rows[_nIndex]["IsFix"];
if (bool(objIsFix)) {%>
<%-- HTML content including server and user controls --%>
<%}Else{%>
<%-- HTML content including server and user controls --%>
<%}%>
'_ nIndex'在cs文件中定义