EmptyDataText Property in the Repeater Control
Posted by Tihomir Ivanov on 27 July 2009 09:51
Rating: 0.00
It seems little strange there isn't provided the EmptyDataText property on the Repeater control. Here's a simple way how to display some text when we've a DataSource with empty content + Repeater:
in the aspx page:
<asp:Label ID="_emptyLabel" runat="server"></asp:Label>
<asp:Repeater ID="_someRepeater" runat="server"
DataSourceID="_someDS" OnPreRender="_someRepeater_PreRender">
<ItemTemplate>
...some data here...
</ItemTemplate>
</asp:Repeater>
<asp:XmlDataSource ID="_someDS" runat="server"></asp:XmlDataSource>
in the code-behind class:
protected void _someRepeater_PreRender(object sender, EventArgs e)
{
try
{
if (_commentsRepeater.Items.Count == 0)
{
_emptyLabel.Text = "still no comments";
}
}
catch (Exception)
{
}
}
cool