Default text for empty Repeater control Default text for empty Repeater control asp.net asp.net

Default text for empty Repeater control


Joaos answer can even be simplified. In the footer, do not set the visible-property of your default item to false, but use the following expression:

<FooterTemplate>    <asp:Label ID="defaultItem" runat="server"         Visible='<%# YourRepeater.Items.Count == 0 %>' Text="No items found" /></FooterTemplate>

This way, you can save the code behind.


Another possibility:

<FooterTemplate>    <asp:Label ID="lblEmptyData" runat="server" Visible='<%# ((Repeater)Container.NamingContainer).Items.Count == 0 %>' Text="No items found" /></FooterTemplate>

The benefit of this code snippet is that you aren't dependent on the ID you assigned to your repeater.


You could workaround the fact that Repeater does not support a inbuilt way to accomplish what you are doing by using the FooterTemplate in conjunction with the OnItemDataBound event and showing the footer only when the data source returns no items.

Examples on how you can do this can be found at:

Handling Empty Data in an ASP.NET Repeater control

How to show Empty Template in ASP.NET Repeater control?