扩展了Repeater控件的EmptyDataTemplate模板功能

(编辑:jimmy 日期: 2024/10/6 浏览:2)

Repeater控件是一个数据显示控件,该控件允许通过为列表中显示的每一项重复使用指定的模板来自定义布局。

相对于GridViews和DataList来说Repeater是一个相当轻巧、灵活的控件,能耗也比它们要小很多。美中不足的是功能略显单薄,尤其是用于绑定的数据源没有数据的情况下,往往要使用一个隐藏面版来显示“暂时没有任何数据”信息。太麻烦了。

于是自行扩展了Repeater控件的EmptyDataTemplate模板已达到同样的效果。

(vs2008)自定义一个Repeater控件,使其具有EmptyDataTemplate模板的功能解决方案-》添加-》新建项目-》选择C#类库
为新建立的类库添加引用 在.NET选项卡中选择System.Web
复制代码 代码如下:
/// <summary>
/// 自定义Repeater 支持EmptyDataTemplate
/// 作者:cantops
/// </summary>
public class Repeater :System.Web.UI.WebControls.Repeater
{
private ITemplate emptyDataTemplate;

[PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(TemplateControl))]
public ITemplate EmptyDataTemplate
{
get { return emptyDataTemplate; }
set { emptyDataTemplate = value; }
}
protected override void OnDataBinding(EventArgs e)
{

base.OnDataBinding(e);
if (emptyDataTemplate != null)
{
if (this.Items.Count == 0)
{
EmptyDataTemplate.InstantiateIn(this);
}
}
}

}

然后制作成为用户控件直接引用使用。
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。