Solved

Querying a Query for Search Panel

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Maps with Webforms 1 29
Need to sort columns in DataGridView 4 36
Starting to use Git with Visual  Studio Online 1 16
c#, case, if 4 16
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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