Solved

Search interface with Gridview results and AJAX

Posted on 2007-04-11
6
479 Views
Last Modified: 2008-01-09
Ok, here's what I want to do, I just need some direction in starting to understand how I may approach this with "good code" in mind:

I have a page, and in it, I have some dropdowns at the top.  At the bottom of the list of dropdowns is a Search Button.

 I want to show a list of records obtained by whatever search logic I encorporate into a GridView.

 Furthermore, I plan on wrapping the GridView control into an ASP.NET AJAX updatepanel with the hopes that I do not get a page refresh.

 I need to first understand how I'd get the search criteria's list results to the same page's GridView, below the search parameter dropdown boxes.
0
Comment
Question by:dba123
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
jasco4617 earned 500 total points
ID: 18891663
Lets say, you have a simple select statement as you search logic, something like this:  SELECT * FROM table WHERE column = @dropdownlistvalue

@dropdownlistvalue would be an asp:controlparameter for your datasource and it woudl be set to the SelectedValue of your dropdownlist.  That way, each time the datasource's databind event is called, it will insert what ever value is selected into you query.

You could use the same principle if you where to use some programming logic instead of a simple query.  In your procedure you could use a switch statement that looks at the selected value of the dropdownlist and the performs a certain type of logic.

- Pat
0
 
LVL 1

Author Comment

by:dba123
ID: 18891701
Yea, I understand that...thanks.  What I'm more concerned with is how the gridview is to be setup and to work once the user clicks search and it binds to the grid to update the list of records retreived
0
 
LVL 1

Author Comment

by:dba123
ID: 18891708
I mean, I have the gridview on my page, now, just need to figure out the backend workings.  I want the gridview to refresh once th euser clicks SEARCH.  Ok, but hmm....how to go about doing this...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Assisted Solution

by:jasco4617
jasco4617 earned 500 total points
ID: 18891775
on you search button include this attribute OnClick="Search_Click"

and in your code, include this procedure:

protected void Search_Click(object sender, EventArgs e) {
    GridView1.DataBind();
}


This is assuming you are C# and that the name of your gridview is GridView1 (the default name).   basically what this will do, is rebind the gridview.

If you wish decide you need to redo the search logic before you call databind(), then you would simply execute that logic before you call DataBind().

The logic you use for the search will need to return a set of data in some form (dataset, datatable, multi-dimensional array, etc...) and the way you would assign that set of data to the datagrid is by calling "GridView1.Datasource = yourdatasource" and that would be done before calling DataBind().

I hope that answers your question.

- Pat
0
 
LVL 1

Author Comment

by:dba123
ID: 18891793
I kinda see what you'r esaying now.  

User clicks Search
All the asp:controlparameter would pass the values to my underlying stored proc.  Since the user clicked Search, in the search onclick I'd do the databind...
0
 
LVL 4

Expert Comment

by:jasco4617
ID: 18891815
Correct.

After the user clicks submit, the gridview would fire the databind procedure, which would then fire the databind procedure for the datasource, which would then pull the selected value from the dropdownlist and then pass it store proc.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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