List<Ticket> ticketList = new List&开发者_C百科lt;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?
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>
You could set the Empty Data Text Property.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatext.aspx
In addition of using the EmptyDataTemplate, you could set your DataSource to null.
List<Ticket> ticketList = new List<Ticket>();
ticketList = _tktBusiness.ReadAll(_tkt);
if (ticketList.Count > 0)
{
gridTicketList.DataSource = ticketList;
}
else
{
gridTicketList.DataSource = null;
}
gridTicketList.DataBind();
Or you could remove the if and bind it even if the ticketList is empty.
List<Ticket> ticketList = new List<Ticket>();
ticketList = _tktBusiness.ReadAll(_tkt);
gridTicketList.DataSource = ticketList;
gridTicketList.DataBind();
精彩评论