6
2009
Empty Item Template for asp:Repeater
The default repeater control does not come with a case for when the datasource is null or empty. This presented somewhat of a problem for me, so I figured I would post my solution so that others could make this change as well. I have uploaded the dll file, you can download it at the end of this post.
[ToolboxData("<{0}:CustomRepeater runat=server>{0}:CustomRepeater>")]
public class CustomRepeater : Repeater
{
#region Public Properties
[Category("Data")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate EmptyTemplate
{
get;
set;
}
#endregion
#region Protected Overrides Methods
protected override void CreateChildControls()
{
base.CreateChildControls();
HandleEmptyData();
}
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
HandleEmptyData();
}
#endregion
#region Private Methods
private void HandleEmptyData()
{
if (this.Items.Count <= 0 && EmptyTemplate != null)
{
this.Controls.Clear();
HeaderTemplate.InstantiateIn(this);
EmptyTemplate.InstantiateIn(this);
FooterTemplate.InstantiateIn(this);
}
}
#endregion
}
After compiling this into a bin it can be implemented in the following way:
<%@ Register TagPrefix="MC" Namespace="MyControls" Assembly="MyControls" %>
Tags: repeater, empty template, .net
Categories: .NET
Post a Comment
You must be logged in to comment.
Wait! Keep Reading! This site uses OpenID for authentication. You DO NOT need to create an account on this site (in fact you can't), you can login using an ID you likely already have. I do not store any information about you, I just am trying to avoid spam.
Comments (0)