使用项目模板[ASP]中的“如果条件" [英] Use the 'If condition' in Item Template [ASP]
本文介绍了使用项目模板[ASP]中的“如果条件"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个要素; ItemTemplate
中的<img>
和<% # Eval ("Url")%>
以选择要显示的元素.
I have two elements; <img>
and <video
> in an ItemTemplate
, I want to test the value <% # Eval ("Url")%>
to choose an element to display.
<itemtemplate>
<li>
<video data-cycle-cmd="pause" id='my-video' class='video-js' controls preload='auto' width='980' height='452' poster='MY_VIDEO_POSTER.jpg' data-setup='{}'>
<source src='<%# Eval("Url") %>' type='video/mp4'>
</video>
</li>
<li>
<img src="<%# Eval("url") %>">
</li>
</itemtemplate>
推荐答案
您可以在模板中使用三元运算符,并根据结果显示/隐藏正确的元素.
You can use a ternary operator in the template and based on that outcome show/hide the correct element.
<ItemTemplate>
<li>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible='<%# Eval("SomeValue").ToString() == "video" ? true : false %>'>
<video data-cycle-cmd="pause" id='my-video' class='video-js' controls preload='auto' width='980' height='452' poster='MY_VIDEO_POSTER.jpg' data-setup='{}'>
<source src='<%# Eval("Url") %>' type='video/mp4'>
</video>
</asp:PlaceHolder>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Url") %>' Visible='<%# Eval("SomeValue").ToString() == "video" ? false : true %>' />
</li>
</ItemTemplate>
这篇关于使用项目模板[ASP]中的“如果条件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文