Solved

Querying a Query for Search Panel

Posted on 2014-11-26
4
77 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 1

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 1

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now