ASP.NET GridView Tutorial
Lesson 131 of 301 · EmptyDataText and EmptyDataTemplate properties of asp.net gridview control – Part 27 · Database
EmptyDataText and EmptyDataTemplate properties of asp.net gridview control – Part 27
Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat/playlists
Link for text version of this video
http://csharp-video-tutorials.blogspot.com/2013/03/emptydatatext-and-emptydatatemplate.html
EmptyDataText and EmptyDataTemplate properties of asp.net gridview control – Part 27
By default an asp.net gridview will not display anything on the webform, if there are no rows in the datasource to which the gridview is bound. For example, let us say we are binding a gridview control to tblProduct table. If there are no rows in this table, then the gridview does not render any thing on the webform. If there are no rows, I want the gridview to display a message stating – “There are no products to display”. There are 2 ways to achieve this.
1. Set EmptyDataText property of the gridview control
OR
2. Use EmptyDataTemplate
EmptyDataRowStyle Property can be used to set the display styles of the empty data row.
If you set both, EmptyDataTemplate is used instead of EmptyDataText. The difference, between the 2 is that, if you want to have greater on what you want to display, then use EmptyDataTemplate.
For example, I want the gridview to render an HTML table with a header and a message
To achieve this I would use EmptyDataTemplate