extended the Repeater control's EmptyDataTemplate template feature _ Practical tips

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 to GridViews and DataList, Repeater is a lightweight, flexible control that consumes a lot less energy than they do. The drawback is that the function is slightly thin, especially for the binding data source without data, often to use a hidden surface version to display "Temporarily no data" information. It's too much trouble.

The Repeater control's EmptyDataTemplate template has been extended to achieve the same effect.

(VS2008) Customizing a repeater control to have a functional solution with EmptyDataTemplate template-add-New Project-"Select C # Class Library
Add a reference to the newly created class library select System.Web in the. NET tab
Copy Code code as follows:

<summary>
Custom Repeater Support 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 make a direct reference to the user control to use.

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.