Solved

Querying a Query for Search Panel

Posted on 2014-11-26
4
79 Views
Last Modified: 2014-12-24
I don't even know what to "search" under on google to find the answer. I've tried a few things and the results don't have anything like I'm looking for, so I'll ask here.

You know those car dealership websites where they have you search for cars and then on the left is a search panel with a bunch of checkboxes. It shows there are:
Fords (22)
Hondas (13)

Then you can click just Hondas and it gets rid of the Fords and shows only the Hondas. And same with models, colors, etc. etc.

That's the type of search I want to do.

How does one do the query involved in that? Are they creating a main sql and using some kind of dataset and searching within that dataset? Or what exactly is happening with the query and data behind the scenes?

I don't need to know how to ajax the boxes and such, just how to handle that query. Those sites are pretty fast when returning data and I'd like to use best practices on this and not try to figure out what I think is going on. If you don't know, please don't respond, I'd prefer not to get guesses and would like an answer from someone who knows how to do it for certain.

thanks!
0
Comment
Question by:Starr Duskk
  • 2
4 Comments
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 200 total points
ID: 40467356
It's essentially a GROUP BY that goes something like this:

SELECT MakeName, COUNT(Make) as the_count
FROM YourTable
WHERE -- whatever the user selects
GROUP BY MakeName

Open in new window


Then if the user clicks on one it'll show the details like this:
SELECT yabba, dabba, doo
FROM cars
WHERE MakeName='{whatever the user clicked on}'

Open in new window

For a frienly tutorial on grouping visit SQL Server GROUP BY Solutions
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 40469328
I understand grouping, I guess I just thought as quick as those search panels come up and when the user clicks the checkboxes the results come up quickly, I thought maybe there was something quick going on. Like maybe you start with a dataset of everything, and then you query against the dataset or something.

I can do all of the above individually as queries, I just figured there was some magic I was missing to make it streamlined and quick. So nothing special is going on?

Every single checkbox group is queried for the search panel for the count?
then when you click a checkbox every single click rebuilds the query and displays the results?
and so on?

that part is easy to do. But it just seems so tedious to hit the database that many times so I thought something else might be going on that I didn't know about.

thanks!
0
 
LVL 8

Accepted Solution

by:
Ashutosh Vyas earned 300 total points
ID: 40475339
Load all your data at the beginning into a DataTable and put that Datatable as the source for your gridview (I am assuming you are displaying your data in the gridview).

When the checkboxes are checked, construct the filters for datatable and rebind.
Something like

   
 dt.DefaultView.RowFilter = "MakeName= '" + filterText + "'";
    gvList.DataSource = dt.DefaultView;
    gvList.DataBind();

Open in new window

0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 40477867
Ashutosh,

thanks! that's more in line with what I thought might be happening. I'll try it out within the next week or so and let you know if I have further questions. thanks so much!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Open a link in vb.net 2 16
VB.NET Textbox input validation 4 37
How to use NFS (Network File System) in Asp.net mvc 5? 4 43
How to repeat the data 4 17
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question