ASP.Net List View EmptyItemTemplate not displaying
It looks like you're confusing EmptyItemTemplate, which is rendered when there are no more data items to display in the last group of the current page, with EmptyDataTemplate, which is rendered when the data source does not contain any records.
From your question, it seems you need the latter. You should write:
<EmptyDataTemplate>
<p>Empty text that will be displayed.</p>
</EmptyDataTemplate>
Crab Bucket
Although its scent still lingers on the form of a flower has scattered away For whom will the glory of this world remain unchanged? Arriving today at the yonder side of the deep mountains of evanescent existence We shall never allow ourselves to drift away intoxicated, in the world of shallow dreams.
Updated on July 16, 2022Comments
-
Crab Bucket almost 2 years
I'm binding a ListView to a collection of objects which is working fine. Unfortunately when the collection is empty then I'm not getting the text in the EmptyItemTemplate element displayed as I would expect.
Markup code is
<asp:ListView ID="lvBuildingContactsGrid" runat="server" onitemcommand="lvBuildingContactsGrid_ItemCommand" > <LayoutTemplate> <!-- some more html markup --> <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> <!-- some more html markup --> </LayoutTemplate> <ItemTemplate> <!-- some item makup --> </ItemTemplate> <EmptyItemTemplate> <p> empty text that isn't displaying </p> </EmptyItemTemplate> </asp:ListView>
The code behind to bind is
ContactRoleCollection contactRoles = new ContactRoleCollection(); contactRoles.ContactRoleSearchByBuildingID(int params); lvListView.DataSource = contactRoles; lvListView.DataBind();
When the collection returns a count of zero then the EmptyItemTemplate text doesn't display. I have viewed the page source and it isn't rendered at all (rather than being hidden). I have replaced the DataSource object just with null i.e.
lvListView.DataSource = null
Just to test it and it still doesn't work. No text rendered again.
I have had this problem on other pages I have worked on (and given up and done kludge work arounds) so it's obviously just something that I am missing - doing incorrectly.
Any input appreciated
-
citronas over 13 yearsMaybe this won't be rendering if you assign null as datasource. (Don't forget the .DataBind() ) Just use the 4 lines of code from above.
-
Crab Bucket over 13 yearsThat was exactly it. Many Thanks