Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show No record found in GridView if binded datasource is List Collection

Tags:

asp.net


I have a gridview in which dtasource binded is a List which returns class type. If no records in list, I want to display 'No records found' in GridView.

List<Ticket> ticketList = new List<Ticket>();
ticketList = _tktBusiness.ReadAll(_tkt);
if (ticketList.Count > 0)
{
    gridTicketList.DataSource = ticketList;
    gridTicketList.DataBind();
}
else
{
}

In else part, what code i have to write to get desired output?Can anybody help?

like image 896
user42348 Avatar asked Jan 20 '23 06:01

user42348


1 Answers

You could use EmptyDataTemplate property of your grid. It gets or sets the user-defined content for the empty data row rendered when a GridView control is bound to a data source that does not contain any records. E.g.

<asp:gridview ...

    <emptydatatemplate>
        No Data Found.  
    </emptydatatemplate>

</asp:gridview>
like image 195
Oleks Avatar answered Jan 31 '23 02:01

Oleks