ListView Control in ASP.NET 3.5 – 2
This post is actually a continuing demonstration of this one:
• ListView Control in ASP.NET 3.5 – 1 (opens a new window)
It would be a better practice to jump into it first before reading this post.
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.
This post is continued by: