如何有条件地显示在DetailsView控件的ItemTemplate /隐藏链接 [英] how to conditionally show/hide link in DetailsView ItemTemplate
本文介绍了如何有条件地显示在DetailsView控件的ItemTemplate /隐藏链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我新的ASP.NET,我试图找出如何,只显示code的一大块在.aspx文件,如果值不为null或空白。下面是我的,内 DetailsView控件
:
I'm new to ASP.NET, and I'm trying to figure out how to only show a chunk of code in the .aspx file if a value is not null or whitespace. Here's what I have, within a DetailsView
:
<asp:TemplateField HeaderText="Phone">
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtPhone" Text='<%# Bind("Phone") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<a href="tel:<%# Eval("Phone") %>">
<i class="icon-phone"></i>
<%# Eval("Phone") %>
</a>
</ItemTemplate>
</asp:TemplateField>
我要有条件地隐藏整个 A
标记是否评估(手机)
为空或空白。我想preFER做这一切的标记,而不是在$ C $做一些C-落后。
I want to conditionally hide the whole a
tag if Eval("Phone")
is null or whitespace. I would prefer to do this all in the markup, as opposed to doing something in the code-behind.
推荐答案
大卫的回答我指出了正确的方向:
David's answer pointed me in the right direction:
<asp:HyperLink runat="server" NavigateUrl='tel:<%# Eval("Phone") %>'
Visible='<%# !string.IsNullOrWhiteSpace(Eval("Phone").ToString()) %>'>
<i class="icon-phone"></i>
<%# Eval("Phone") %>
</asp:HyperLink>
这篇关于如何有条件地显示在DetailsView控件的ItemTemplate /隐藏链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文