Feb 12 2009
ASP.NET empty Repeater problem
I was looking for a way to solve the problme of the repeater Control in ASP.NET, which does not offer a functionality like the Empty Data Template of the GridView control or other controls. A solution would be to inherit the Repeater control and create an EmptyTemplate element, as in this post. After some searches I fount this interesting post. The author uses the HeaderTemplate and checks the DataItem count, if it is 0 it shows some text (in the example, it shows a tabel row, but you could easuly do the same with a div or span), otherwise it is hidden. Just what I was looking for! This is the code to use:
<asp:Repeater ID=”repeater” runat=”server”
DataSourceID=”mydatasource” >
<HeaderTemplate>
<span id=”span1″ runat=”server” visible=’<%# ((ICollection)repeater.DataSource).Count == 0 ? true : false %>’>
No data found.
</span>
</HeaderTemplate>
Here repeater is the Id of the Repeater Control.



Default
Small Fonts
Big Fonts