Empty Data display for asp net Repeater
Category: DotNet
If you use the Repeater a bit, you'll notice it does not have a EmptyRows template, which is kind of lame. I don't know why Telerik hasn't built their own cool repeater which would be quite useful. Anyways, to show an empty message when the row count is zero, add an OnItemDatabound event, and check the Repeater1.Items.Count == 0. If so, you can show hide some label. Below is some sample code, using the Footer in the repeater for your empty message.
protected void RepeaterUpcomingReservations_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (RepeaterUpcomingReservations.Items.Count == 0)
{
if (e.Item.ItemType == ListItemType.Footer)
{
Label lblFooter = (Label)e.Item.FindControl("LabelEmpty");
lblFooter.Visible = true;
}
}
}