Vara Prasad.M
Vara Prasad.M

Reputation: 1550

How to get custom message for ListView when there are no rows

I need to show "There are no records" message when there are no rows for list view i want to show the message.

How can i do this?

Thanks.

Upvotes: 1

Views: 4258

Answers (3)

Sukesh Marla
Sukesh Marla

Reputation: 177

Use the following markup:

<asp:ListView runat="server" ID="LstCustomer">
    <EmptyDataTemplate>
        Customer not found
    </EmptyDataTemplate>
</asp:ListView>

Upvotes: 2

abatishchev
abatishchev

Reputation: 100248

Extending @Christian's answer:

Using code-bahind:

protected void ListView1_ControlRemoved (object sender, EventArgs e)
{
   var ListView1 = sender as ListView;
   if (ListVeew1.Items.Count == 0)
       ListView1.Items.Add("There are no records");
}

OR using markup:

<asp:ListView runat="server" ID="ListView1">
    <EmptyDataTemplate>
        There are no records
    </EmptyDataTemplate>
</asp:ListView>

Upvotes: 3

You don't say what you are programming in... But I believe the most common way to do this is to actually insert an item with the text "There are no records".

You can use the <EmptyDataTemplate> to specify what to display when the data source is empty.

Upvotes: 1

Related Questions