Empty Data display for asp net Repeater

Posted on: Wed Feb 10 18:02:40 -0800 2010. Updated on: Wed Feb 10 18:03:06 -0800 2010.
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;
				}
			}
		}

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.