Monday, March 14, 2011

ListView Control in ASP.NET 3.5 – 2

EmptyDataTemplate
The empty template, EmptyDataTemplate, can be utilized to define the view when there is no data for the ListView, which means that the ListView control is bound to a DataSource having no records. In reality, this template is rendered instead of LayoutTemplate when ListView is empty. It renders by itself, therefore it is not required to be defined inside any other ListView templates.
I have defined the Select command of AccessDataSource1 in a way that it returns zero record, and put the empty template right after AlternatingItemTemplate between the ListView tags:

In order to hide the “Clear Sorting” and “View All” buttons when our ListView is empty, I will set their visibility values to False inside the Page_Load method when the DataSource (AccessDataSource1) has no records:

As a result of all these changes, the HTML presentation should look like:

It should also be known that…
Even though ListView is empty, EmptyDataTemplate can only be displayed when InsertItemPosition value is set to None (which is the default if the value is not defined). InsertItemPosition defines the location of InsertItemTemplate when it is rendered as a part of ListView.
Download
For further understanding of this post, you can download the source code (by VWD 2008) via here.

No comments:

Popular Posts