locked
how to check if gridview datasource has any rows returned. RRS feed

  • Question

  • User-1930986229 posted

    I have a grid view in my asp application but when no results are returned from the sqldatabase. I want a label to show that no results for the search. How to check i the datasource fetched no rows. help ASAP.....

    Thursday, February 16, 2012 9:48 AM

Answers

  • User-2146987983 posted

    You can use:

    <asp:GridView ID="grid" runat="server">

    <EmptyDataTemplate>No record found</EmptyDataTemplate>

    <Columns>....</Columns>

    </asp:GridView>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 16, 2012 10:16 AM
  • User-1831219222 posted

    you can use emptyDataText:

    <asp:gridview id="CustomersGridView" 
            datasourceid="CustomersSqlDataSource" 
            autogeneratecolumns="true"
            emptydatatext="No data in the data source."
            runat="server">
    
            <emptydatarowstyle backcolor="LightBlue"
              forecolor="Red"/>
    </asp:gridview>

    more here:

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatext.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 16, 2012 12:11 PM

All replies

  • User-2146987983 posted

    You can use:

    <asp:GridView ID="grid" runat="server">

    <EmptyDataTemplate>No record found</EmptyDataTemplate>

    <Columns>....</Columns>

    </asp:GridView>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 16, 2012 10:16 AM
  • User-1831219222 posted

    you can use emptyDataText:

    <asp:gridview id="CustomersGridView" 
            datasourceid="CustomersSqlDataSource" 
            autogeneratecolumns="true"
            emptydatatext="No data in the data source."
            runat="server">
    
            <emptydatarowstyle backcolor="LightBlue"
              forecolor="Red"/>
    </asp:gridview>

    more here:

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatext.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 16, 2012 12:11 PM