In a very simple way you can get both your headers and a message saying that there were no data.
You make your LayoutTemplate
like the following idea:
<LayoutTemplate>
<table>
<tr>
<td>a header</td>
<td>another header</td>
<td>third header</td>
</tr>
<tr runat="server" id="itemPlaceholder">
<td colspan="3"
There is no data!
</td>
</tr>
</table>
</LayoutTemplate>
Notice that the tr
that is the placeholder (marked by id="itemPlaceholder") actually contains something. It contains what should be shown when there is no data. Then, in code behind, you set the <EmptyTemplate>
to be equal to the <LayoutTemplate>
(so that you have only one such template to maintain). I do it like this:
Private Sub lvwThings_Init(sender As Object, e As EventArgs) Handles lvwThings.Init
lvwThings.EmptyDataTemplate = lvwThings.LayoutTemplate
End Sub
The logic then is as follows:
When there is data, i.e. when the actual <LayoutTemplate>
is used, the whole <tr runat="server" id="itemPlaceholder">
, with the td
and text it contains, will be replaced by the <ItemTemplate>
.
But, when there is no data, i.e. when the <EmptyTemplate>
is used (instead of the <LayoutTemplate>
), nothing inside the <EmptyTemplate>
is replaced, so everything is shown as it is.