For showing data in a list format we may use Gridview or Listview or Repeater.
But suppose no data is there for a particular filter or in a particular instance then we should show some custom message to the user saying that no data is there to show or some similar messages.
If we are using Listview for showing custom message (message to show when no data is there), we can use EmptyDataTemplate tag. We can write our custom message inside the tag and it will be shown when no data will be there.
Sorry no item is there to show.
But in Repeater control we do not have any such tags which supports message displaying when no data is present.
There is a way in which you can achieve that, it is described in the following steps:
STEP 1:
In the footer tag of Repeater control we will have a label and which will be hidden (Visible=”false”).
.......
STEP 2:
In ItemDataBound event of Repeater UserControl we will check whether the repeater contains any items / rows or not.
If it doesn’t contain any items then we will find the label present at the footer and will show the label (Visible = true).
protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { Repeater rptDemo = sender as Repeater; // Get the Repeater control object. // If the Repeater contains no data. if (repeaterTopItems != null && repeaterTopItems.Items.Count < 1) { if (e.Item.ItemType == ListItemType.Footer) { // Show the Error Label (if no data is present). Label lblErrorMsg = e.Item.FindControl("lblErrorMsg") as Label; if (lblErrorMsg != null) { lblErrorMsg.Visible = true; } } } }