how to check the listview is empty ?

Posted by Chaithragm under ASP.NET on 3/11/2013 | Points: 10 | Views : 4198 | Status : [Member] | Replies : 4
if the list is empty i have to dosplay the message "no records found"

<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("[stream_id]") %>'></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text='<%# Eval("[name]") %>' Visible="False"></asp:Label>
<iframe id="iframe2" runat="server" frameborder="0" src='<%# "~/pdf_handler.ashx?id=" + Eval("stream_id") %>' style="width:740px;height:550px"></iframe>
</ItemTemplate>
</asp:ListView>




Responses

Posted by: Karthikreddy on: 3/11/2013 [Member] Starter | Points: 25

Up
0
Down
after
</ItemTemplate>
tag add bellow code

<EmptyItemTemplate>

<p> empty text that isn't displaying </p>
</EmptyItemTemplate>


if it display paragraph text .than the list view is empty

k@rth!k
karthikreddy08a50@gmail.com

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikreddy on: 3/11/2013 [Member] Starter | Points: 25

Up
0
Down
if(ListView1.ListItems.Count = 0)

{
//code

}
else
{
//code

}


k@rth!k
karthikreddy08a50@gmail.com

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 3/11/2013 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,

<asp:ListView ID="ListView1" runat="server">
<EmptyDataTemplate>
No records found...
</EmptyDataTemplate>
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("[stream_id]") %>'></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text='<%# Eval("[name]") %>' Visible="False"></asp:Label>
<iframe id="iframe2" runat="server" frameborder="0" src='<%# "~/pdf_handler.ashx?id=" + Eval("stream_id") %>'
style="width: 740px; height: 550px"></iframe>
</ItemTemplate>
</asp:ListView>


Please Mark As Answer if this helps you

.

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chaithragm on: 3/12/2013 [Member] Starter | Points: 25

Up
0
Down
Thank you...

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response