How can I display a message in the place of the GridView if there is no results come from the database?
The GridView has an EmptyDataRow template and style, just make the use of that:
  <asp:gridview id="CustomersGridView" 
    datasourceid="CustomersSqlDataSource" 
    autogeneratecolumns="true"
    runat="server">
    <emptydatarowstyle backcolor="LightBlue"
      forecolor="Red"/>
    <emptydatatemplate>
      <asp:image id="NoDataImage"
        imageurl="~/images/Image.jpg"
        alternatetext="No Image" 
        runat="server"/>
        No Data Found.  
    </emptydatatemplate> 
  </asp:gridview>
example from MSDN GridView.EmptyDataRowStyle Property (available since .NET 2.0)
There is also the EmptyDataText property that you type on the <asp:GridView ... >
EmptyDataText="There is no items in the list box"
and the EmptyDataRowStyle-CssClass to style it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With