Extends the EmptyDataTemplate template function of the Repeater control.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.