NibblyPig NibblyPig - 3 months ago 32
ASP.NET (C#) Question

ListView LayoutTemplate does not show when empty asp.net

I have an

<asp:ListView>
but for some reason the LayoutTemplate section does not show when the list is empty, although the
<EmptyDataTemplate>
section shows. The LayoutTemplate contains the headers for the table, and I want to show an empty table when there are no items in the datasource, not just the content of EmptyDataTemplate.

If there is no choice I will copy the LayoutTemplate into EmptyDataTemplate but it seems stupid to have to do this. Ideas?

Answer

From the MSDN:

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.

the key words here are "...the template is rendered instead of the LayoutTemplate template..."

So I think, you have to copy the LayoutTemplate into the EmptyDataTemplate template.

Comments