The Repeater control is a data display control that allows you to customize the layout by repeatedly using the specified template for each item displayed in the list.
Compared with GridViews and DataList, Repeater is a lightweight and flexible control that consumes much less energy than GridViews and DataList. What is lacking in the US is that the functions are slightly thin, especially when the bound data source does not have data, it is often necessary to use a hidden panel to display "no data temporarily" information. It is too troublesome.
Therefore, the EmptyDataTemplate template of the Repeater control has been expanded to achieve the same effect.
(Vs2008) customize a Repeater control to have the EmptyDataTemplate Template Function Solution-add-Create Project-select C # class library
Add reference for the newly created class library. On the. NET tab, select System. Web.Copy codeThe Code is as follows: // <summary>
/// Custom Repeater supports EmptyDataTemplate
/// Author: 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 );
}
}
}
}
Then it is created as a user control for direct reference.