1 minute read

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


	    public ITemplate EmptyTemplate
        #region Protected Overrides Methods
        protected override void CreateChildControls()
        protected override void  OnDataBinding(EventArgs e)

        #region Private Methods

        private void HandleEmptyData()
            if (this.Items.Count <= 0 && EmptyTemplate != null)


After compiling this into a bin it can be implemented in the following way:

<%@ Register TagPrefix="MC" Namespace="MyControls" Assembly="MyControls" %>

<!--HTML Goes here-->

<form runat=”server”>
    <MC:CustomRepeater id="Repeater1" runat="server">
            <!--Stuff Here - Maybe a ul-->
                Normal stuff here
            <li>No results matched your query.</li>
            <!--Stuff Here -->