Advising users there’s no data with EmptyDataTemplate

Certify and Increase Opportunity.
Govt. Certified ASP.NET Programmer

Advising users there’s no data with EmptyDataTemplate

The empty template is displayed in a ListView control when the data source that is bound to the control does not contain any records and the InsertItemPosition property is set to InsertItemPosition.None. The template is rendered instead of the LayoutTemplate template. If the InsertItemPosition property is set to a value other than InsertItemPosition.None, the EmptyDataTemplate template is not rendered.

You can define a custom user interface (UI) for the empty template by using the EmptyDataTemplate property. To specify a custom template declaratively for the empty template, add and EmptyDataTemplate element inside the ListView control. You can then add the contents of the template to the EmptyDataTemplate element.

The following example shows how to define a custom template for the empty template.

<%@ Page language=”C#” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”

<html xmlns=”” >
<head id=”Head1″ runat=”server”>
<title>ListView EmptyDataTemplate Example</title>
<style type=”text/css”>
.emptyTable { background-color:Aqua; }
<form id=”form1″ runat=”server”>

<h3>ListView EmptyDataTemplate Example</h3>

<asp:ListView ID=”ContactsListView”
<table runat=”server” id=”tblProducts”>
<tr runat=”server” id=”itemPlaceholder” />
<tr runat=”server”>
<asp:Label ID=”FirstNameLabel” runat=”Server” Text='<%#Eval(“FirstName”) %>’ />
<asp:Label ID=”LastNameLabel” runat=”Server” Text='<%#Eval(“LastName”) %>’ />
<table cellpadding=”5″ cellspacing=”5″>
<asp:Image ID=”NoDataImage”
No records available.

<!– This example uses Microsoft SQL Server and connects      –>
<!– to the AdventureWorks sample database. Use an ASP.NET    –>
<!– expression to retrieve the connection string value       –>
<!– from the Web.config file.                                –>

<!– The select query for the following SqlDataSource     –>
<!– control is intentionally set to return no results    –>
<!– to demonstrate the empty data template               –>
<asp:SqlDataSource ID=”ContactsDataSource” runat=”server”
ConnectionString=”<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>”
SelectCommand=”SELECT [ContactID], [FirstName], [LastName] FROM Person.Contact WHERE [ContactID]=1000″>


Get industry recognized certification – Contact us