Displaying "Sorry there were no results for your search" when a search yields no results

Discussion in 'Databases' started by luke_jack61188, Jul 8, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hello,


    I've got an SQL datasource and a GridView control on a page called textsearch.aspx (in a VS web application). The text that the user is searching for is passed in as a querystring - e.g. if the user searches for "clematis" he's navigated to textsearch.aspx?Search=clematis. This all works fine as long as there is something that's called "clematis" (or whatevers being search for) in my database. However, if there are no matches in my database nothing is displayed (except for what's on my master page).


    I need to be able to display a message which says something to the effect of "Sorry there were no results for your search" if there are no matches in my database. Could someone please tell me how I can achieve this?


    Many thanks,


    Luke
     
  2. I usually just have a seperate control on the page like this:

    <p runat='server' id='_noMatchesLabel'>Sorry! No results found!</p>

    Then when you query the database, just check if there is at least one result, then show or hide both the label and your DataGrid.

     
  3. Okay - thanks.

    Does anyone have the VB code for this?

    Cheers,
    Luke
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    Try this

    Dim dv as DataView = GetResults()

    if(dv.Count > 0) Then

    _noMatchesLabel.Visible = false

    else
    _grid.Visible = false

    End If

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  5. Thanks for all your help - it's much appreciated.

    Just incase there's anyone else out there trying to do the same thing, I've found the easiest way to do it is just to type the "Sorry there will no results for your search" text into the EmptyDataTemplate of the grid view. This way it's easy to include pictures and anything else you might want to include on the page if there are no results.

    Thanks again,
    Luke
     
  6. "EmptyDataTemplate" is new to the GridView object and is not available in the Repeater or DataGrid.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page