ASP.Net list view EmptyItemTemplate not showing

I am linking a ListView with a collection of objects that work fine. Unfortunately, when the collection is empty, I do not get the text in the EmptyItemTemplate element as I expected.

Markup code

<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 binding code is

  ContactRoleCollection contactRoles = new ContactRoleCollection(); contactRoles.ContactRoleSearchByBuildingID(int params); lvListView.DataSource = contactRoles; lvListView.DataBind(); 

When the collection returns a zero count, the text EmptyItemTemplate is not displayed. I looked at the source of the page and it is not displayed at all (and not hiding). I replaced the DataSource object with only null ie

 lvListView.DataSource = null 

Just test it and it still doesn't work. The text is not displayed again.

I had this problem on other pages that I worked on (and did not work and did kludge work arounds), so this is clearly just what I am missing is wrong.

Any input is appreciated.

+8
c # webforms
source share
1 answer

It looks like you are confusing the EmptyItemTemplate , which is displayed when there are no more data items to display in the last group the current page with the EmptyDataTemplate , which is displayed when the data source does not contain records.

From your question, it seems you need the last one. You must write:

 <EmptyDataTemplate> <p>Empty text that will be displayed.</p> </EmptyDataTemplate> 
+23
source share

Source: https://habr.com/ru/post/650661/


All Articles