列表视图/ DetailsView控件:隐藏空场 [英] Listview/DetailsView: Hide a null field

查看:192
本文介绍了列表视图/ DetailsView控件:隐藏空场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这是一个相当普遍的问题,但至今我还没有找到一个很好的解决方案。

I imagine this is quite a common problem, but as yet I haven't found an elegant solution.

我公司拥有一批在那里我有任何一个ListView或绑定到一个SQL Server存储过程DetailsView控件实例。我的问题是,有许多情况,其中,当列是空的,我想显示的东西在UI不同。一个典型的例子是,我有一个呈现为一个LinkBut​​ton(在列表视图)或作为HyperLinkField字段(在DetailsViews)的URL列 - 返回NULL URL的时候,我的渲染,没有src属性链接。理想情况下,我的要在这种情况下,以显示任何在该领域

I have a number of instances where I have either a ListView or a DetailsView control that is bound to a SQL Server SProc. The problem I have is that there are numerous instances where, when a column is Null, I want to display something different in the UI. A typical example would be where I have a URL column that is rendered as a LinkButton (in the ListViews) or as a HyperLinkField (in the DetailsViews) - when a Null URL is returned, I'm rendering links with no src attribute. Ideally, I's want to display nothing in this field in such a scenario.

在每种情况下,则返回空值的时候,我怎么能跳过/改变该项目的渲染?

In each of these cases, when a null value is returned, how can I skip/alter the rendering of that item?

先谢谢了。

更新:我还没有机会真正尝试这些了,但都有益的建议。我想我喜欢里克斯回答最好,但再次感谢别人...

Update: I haven't had chance to actually try these out, but all helpful suggestions. I think I like Ricks answer the best, but thanks again to the others...

推荐答案

标记:

 <asp:HyperLink id="whatever" runat="server" 
  NavigateURL='<%# Eval("url") %>' Visible='<%# IsVisible(Eval("url")) %>' />

后面的 code:

protected bool IsVisible(object obj)
{
     bool result = false;

     string url = (string)obj;
     if(!string.IsNullOrEmpty(url))
     {
          result = true;
     }

     return result;

}

这篇关于列表视图/ DetailsView控件:隐藏空场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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