WebForms: handling an empty data source in a Repeater control
I have a Repeater generating an unordered list: <ul> <li>item 1</li> <li>item 2</li> ... </ul> The problem occurs when the data source has no items. Most of the articles I found add a Label control to the Repeater 's FooterTemplate , but I can't do that here (I need a li tag). Here are two methods I have confirmed to be working: Method 1: using the OnItemDataBound event Use the following HTML: <asp:Repeater runat="server" ID="Repeater1" OnItemDataBound="Repeater1_ItemDataBound"> <HeaderTemplate> <ul> </HeaderTemplate> <ItemTemplate> <li> <asp:Label runat="server"> <%# DataBinder.Eval(Container.DataItem, "Name") %> </asp:Label> </li> </ItemTemplate> <FooterTemplate> <li runat="server" id="noData" Visible="False">[None found.]</l...