擴展了Repeater控件的EmptyDataTemplate模板功能
更新時間:2013年01月08日 10:30:23 作者:
Repeater控件是一個數(shù)據(jù)顯示控件,該控件允許通過為列表中顯示的每一項重復(fù)使用指定的模板來自定義布局
Repeater控件是一個數(shù)據(jù)顯示控件,該控件允許通過為列表中顯示的每一項重復(fù)使用指定的模板來自定義布局。
相對于GridViews和DataList來說Repeater是一個相當輕巧、靈活的控件,能耗也比它們要小很多。美中不足的是功能略顯單薄,尤其是用于綁定的數(shù)據(jù)源沒有數(shù)據(jù)的情況下,往往要使用一個隱藏面版來顯示“暫時沒有任何數(shù)據(jù)”信息。太麻煩了。
于是自行擴展了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);
}
}
}
}
然后制作成為用戶控件直接引用使用。
相對于GridViews和DataList來說Repeater是一個相當輕巧、靈活的控件,能耗也比它們要小很多。美中不足的是功能略顯單薄,尤其是用于綁定的數(shù)據(jù)源沒有數(shù)據(jù)的情況下,往往要使用一個隱藏面版來顯示“暫時沒有任何數(shù)據(jù)”信息。太麻煩了。
于是自行擴展了Repeater控件的EmptyDataTemplate模板已達到同樣的效果。
(vs2008)自定義一個Repeater控件,使其具有EmptyDataTemplate模板的功能解決方案-》添加-》新建項目-》選擇C#類庫
為新建立的類庫添加引用 在.NET選項卡中選擇System.Web
復(fù)制代碼 代碼如下:
/// <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);
}
}
}
}
然后制作成為用戶控件直接引用使用。
相關(guān)文章
asp.net core webapi文件上傳功能的實現(xiàn)
這篇文章主要介紹了asp.net core webapi文件上傳功能的實現(xiàn),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12
ASP.NET The system cannot find the file specified解決辦法
這篇文章主要介紹了ASP.NET The system cannot find the file specified解決辦法的相關(guān)資料,需要的朋友可以參考下2016-11-11
asp.net Silverlight應(yīng)用程序中獲取載體aspx頁面參數(shù)
有時候SL應(yīng)用中需要使用由aspx頁面中傳遞過來的參數(shù)值,此時通常有兩種方法獲取2009-11-11

