Render empty repeater

Max Al Farakh picture Max Al Farakh · Jul 5, 2011 · Viewed 8.5k times · Source

When Repeater contains no items it's not get rendered in HTML at all, even HeaderTemplate or FooterTemplate. I need to manipulate it on client-side even if it's empty.

Is there any way to always render Repeater in HTML?

Answer

Saurabh picture Saurabh · Jul 5, 2011

In the <FooterTemplate>, add a Label with some empty data text and set its visible property to false.

<FooterTemplate>
<table>
 <tr>
 <td>
 <asp:Label ID="lblEmptyData"
        Text="No Data To Display" runat="server" Visible="false">
 </asp:Label>
 </td>
 </tr>
 </table>           
 </FooterTemplate>

Now check the the data while binding repeater, if no rows return then make label visible otherwise no action.

More details here.