GridView Filtering and Searching

Hello Everyone,
i'm having a gridview wich list clients details. i have setup a search text box and a  dropdownlist for filtering. Everything is working except when i try to navigate the next page....i'm getting the filter results and not the search ones....i have created a Hidden control and store the search value... i'm still having problem with this.
Anyone have a solution or run into similar situation?

7/4/2008 9:44:13 AM 93655 articles. 6 followers. Follow

10 Replies

Similar Articles

[PageSpeed] 20
Get it on Google Play
Get it on Apple App Store

You will need to store the filtered selectcommand in Session and then reuse this saved selectcommand when postback occurs or the page will default back to you first selectcommand.

Hope it helps

If this has helped Please: Don't forget to click "Mark as Answer" on the post that helped you.
That way future readers will know which post solved your issue.
7/4/2008 4:22:30 PM

i'm getting the filter results and not the search ones

Hi lidadil,

I think u need to store the value of Textbox though which i can get the search result.


HttpContext.Current.Items.Add("txtSearch", txtSearch.Text)

Now, when u postback to other page using Server.Transfer

u can get the SearchTextBox value using



if u can use DirectCast(PreviousPage.FindControl("txtSearch"), TextBox).Text to get the value of textbox to generate SelectCommand in Next Page.

If i miss understood ur requirement, plz tell me.

Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
7/5/2008 4:33:27 AM

Thank you for reply.

The gridview has a paging set to true.  Now when i  search and get more than one page results, the navigation to the page n return the filter results.

I'm not using selectcommand, i'm using LINQ and adding the results to the gridview.

Code snapshot: 


1        Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
3            If ddlFilter.SelectedValue <> "" Then
4                Hidden.Value = txtSearch.Text
5                ClientGV.DataSource = GetClients(Trim(Hidden.Value), "NAME")
6                ClientGV.DataBind()
7            End If
8        End Sub
11       Protected Sub ddlFilter_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlFilter.SelectedIndexChanged
12           If (ddlFilter.SelectedValue <> "") Then
13               txtSearch.Enabled = True
14               btnSearch.Enabled = True
15           Else
16               txtSearch.Enabled = False
17               btnSearch.Enabled = False
18           End If
20           ClientGV.DataSource = GetClients(ddlFilter.SelectedValue, "VENUE")
21          ClientGV.DataBind()
24       End Sub
27       Protected Sub ClientGV_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles ClientGV.PageIndexChanging
28           If Hidden.Value <> "" Then
29               ClientGV.DataSource = GetClients(Trim(Hidden.Value), "NAME")
30           ElseIf ddlVenue.SelectedValue <> "" Then
31               ClientGV.DataSource = GetClients(ddlFilter.SelectedValue, "VENUE")
32           End If
33           ClientGV.PageIndex = e.NewPageIndex
34           ClientGV.DataBind()
35       End Sub
Also i noticed that the Dropdownlist SelectedIndexChanged Event is called in page postback too,which causes my Hidden control value to be initialised not only on user interaction with the DropDownList but also with page postback!!
I'm missing something?


7/5/2008 9:03:31 AM

Hi lidadil,

I think if u have stored the value in Hidden Control then on postback it must be maintained.

However, rather than using hidden control to store the value, u can make use of ViewState.

like ViewState("txtSearch") = txtSearch.Text

and then Check

If ViewState("txtSearch") IsNot Nothing and ViewState("txtSearch") <> "" Then



Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
7/5/2008 10:42:22 AM

Hi Coool,

Thank  you for your help.

I'm using the Hidden control to check if the user is searching or when the user press search button, i store the textbox value into the hidden control. if the user filter (DropDownList index Changed) i reset the hidden control value.

My problem is even the user does not change the current value of Dropdownlist, the Hidden control value get initialized,

 i.e the below code is executed! and that happening when i move to the next page.

Protected Sub ddlFilter_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlFilter.SelectedIndexChanged
12           If (ddlFilter.SelectedValue <> "") Then
13               txtSearch.Enabled = True
14               btnSearch.Enabled = True
15           Else

16               txtSearch.Enabled = False
17               btnSearch.Enabled = False
18           End If


20           ClientGV.DataSource = GetClients(ddlFilter.SelectedValue, "VENUE")
21          ClientGV.DataBind()
24       End Sub

  How to make sure that Hidden.value is initialized only when the user change the dropdown selected value?

Unfortunately i'm not using ViewState in my application (Viewstate disabled)




7/5/2008 12:13:42 PM

Hi lidadil,

U have disabled ViewState, that's why ur hidden field's value is not maintained during postback.

If possible then only disable ViewState of the Controls which are unnecessarily load ur page size.

Refer this article to decide the ViewState of Control

In such condition, u have to use Session to Store the Value of txtSearch.Text

Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
7/6/2008 5:50:01 AM

Hi Coool,

Thank you for your reply.

In SelectedIndexChanged event  if i remove the statement that reset the Hidden control (Hidden.value=""), the value is maintained during Gridview pagination.

My Problem:

The Hidden control value is reset in page postback during pagination (SelectedIndexChanged event called !! )

My ONLY requirement:

When the user change the selected dropdownlist value, the hidden control value should be reset to empty String.



7/6/2008 7:12:31 AM

Any help is highly appreciated.



7/8/2008 5:51:32 AM

I'm still waiting for any answer Sad


7/13/2008 5:47:35 AM

if your hidden field is loosing its value, place it inside updatepanel and check in your cs and aspx and javascript u r not clearing its value.....

Amit Ranjan

If it helped you Don't Say Thank You, Instead Mark it as Answer... Doing so will help you and will also help others..
12/9/2008 8:59:37 AM

Similar Artilces:

Gridview Search: use DropDownList and TextBox to search / filter gridview?
Let's say I have a gridview with three columns: First Name, Last Name, ID Number.  Here's an example of what I want to do:I want to display all the records in the gridview to start.  There would be a dropdownlist that lets the user select whether to search by first name, last name, or ID number and a text box that lets them type in what they want to search for (and a button to start the search).  After searching, the gridview would only display the records that matched the criteria.The gridview needs to be editable, sortable, and pageable even after searching/filtering...

Implementing .Net Form into an web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Gridview Search Without Object Datasource Filter ParametersGridview Search Without Object Datasource Filter Parameters
Couple weeks ago I read a article about highlighted search in Gridview  ( and in my project I used things I learned but now things changed I have a gridview and in code I give its datasource so because I dont use any objectdatasource I dont know where to write my filtering parameters. Is there anyway to use filtering without objectdatasource, or is there a way to give objectdatasource an source then bind it to my gridview. My code:  //No objectdatasource how can I conduct a search?GridView1.Da...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

Searching for a form name (present in a different web form)
Searching for a form name (present in a different web form) I have a web form (webform1) where all available forms are displayed. Another web form (webform2) where i have few or no alerts for one or each or none of the forms on the webform1. I have to place an icon or something to the next of the forms on webform1 to notify users about the alerts. What is the possible way to do this. Please give some suggestions. Thanks Hey, Not quite sure what you are looking for... could you explain in more depth, or post some code to help look at it? BrianBrian"Trust in the Lord and d...

.Net Web Form & Web Service Deployment
Hi all I have written some test web services and some web form applications and deployed them to my IIS. That's fine but I now want to deploy them to my real IIS server. I have created an msi for each but the problem is I seem to only be able to deploy to the default web site. Our default web site is turned off and instead we use several other sites. Does anybody happen to if Powerbuilder 11 supports non default web sites? If not do I need to hack the msi and if so can anybody suggest a suitable tool. I have Orca but it's not very friendly. Unless of course I knew exactly w...

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Best practice for web form with Form View and multiple Dependent Gridviews?
Hi I have a web form to display an open job against an equipment item. I have a Formview for the static data about the job, then I have a Gridview for documenting work against the open job and yet a third Gridview embeded within the first Gridview to document personnel and labor hours for each line of work taken. It looks ok if there is data to display in the gridview but there is nothing there when no data has been entered against the job.  How do I get the webform to show the headers in the gridview even if there is no data?    Your simpliest way to acomplish this ...

For interrupting.web form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form
Web Form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form ! Because of my pool English, if you can't see , I will explain more ! ThanksGambler is the real life I guess you mean when form grows it also grow parent div element. This is normal. If you want div to stay fixed size and rather clip the form and maybe show a scrollbar, look at overflow property in CSS.Thanks------------------------------------------------------------This posting is provided "AS IS" with no warranties, and confers no ...

calling a web form from another web form
I would like to know what is the best way to open a web form from another web form. I would like to call it from a button control. Thanks Well, if I've grasped your question right, there are many methods to do that: 1)Response.Redirect > To navigate to another page from code and is equal to clicking a hyperlink. I suggest this as I think it's closer to your question. 2)Server.Transfer > This ends the current web form and begins a new web form. It's usable when you want to pass some variables i.e (Label1.Text) to the next immediate page. It's not safe though and not used to send p...

Web Form embedded in another Web Form
Hi,  I have programmed a Web Form which acts like a scientific calculator. I would like to embedd this calculator in the upper left hand corner of another accounting Web Form. I don't want to host the calculator on the same server as the accounting page. I.e. I want them to have distinct URLs. Classically, I would do this using frames, but is there a better way using ASP? Is there some sort of Panel which can display the webpage at a specific URL which I can just drag onto my accounting Web Form? Thanks,  P1000   Frames are the only way to embed a webform inside ano...

Could PB .NET Web Form POST security Information to others web page??
This is a multi-part message in MIME format. ------=_NextPart_000_00F9_01C9C4D5.8FB45C90 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: quoted-printable Hi,=20 Have anyone came across the requesion to POST security informations from = PB .NET web form web page to other web site?? I have tried many datys, Could any kind man give me some suggessions?? thanks & Best regards Leon ------=_NextPart_000_00F9_01C9C4D5.8FB45C90 Content-Type: text/html; charset="big5" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML P...

How to fire events in other web form from other web form ?
Suppose that I have A and B web form. I want to trigger B web form's Page_Load event from A web form. How can I do that ? Thanks in advanced WilbertWilbert Bujn Create a public method in B that call the load method : public void Load(object sender, System.EventArgs e) { Page_Load(sender, e) ; } In the page_load of A, instanciate a B object and then call the function B myB = new B() ; myB.Load() ; Quicky Thank you quicky, it works fine. WilbertWilbert Bujn...

How To Convert web template to Forms Template
I need  Convert web template to Forms Template   There are some free c# to vb converters out there which will allow you to upload a project and convert it to vb.   The programming models for windows forms and web projects are very different there is no way to convert a web to windows forms project.      Silverlight-helpVb TipsSpace Coast .Net User Group Hey Ajax-y, This tool really helps all programmers. I thought I would share this wit...

Web resources about - GridView Filtering and Searching -

Bayesian spam filtering - Wikipedia, the free encyclopedia
/ ˈ b eɪ z i ə n / BAY -zee-ən ; after Rev. Thomas Bayes ) is a statistical technique of e-mail filtering . It makes use of a naive Bayes classifier ...

Facebook Adds Filtering To Messages, Tests Paid Service
Facebook released an update to its messaging system on Thursday , adding a filtering system and introducing a paid service for U.S. users who ...

Facebook to test option for paid messages between users, announces new filtering controls
... users to pay to send direct messages to another user’s inbox rather than their “other” folder. The social network is also releasing new filtering ...

Filtering mentions - Twitter Blogs
As part of our product development process, we regularly reach out to our partners to better understand what would improve the Twitter experience. ...

ibisMail Free - Filtering Mail on the App Store on iTunes
Get ibisMail Free - Filtering Mail on the App Store. See screenshots and ratings, and read customer reviews.

Google AdSense Category Filtering - Flickr - Photo Sharing!
Details at

Australia's piracy web filtering - an exercise in futility
Even school children will laugh at the token gesture of blocking The Pirate Bay.

Internet Filtering Scheme's Demise Welcomed
Opponents of Stephen Conroy's mandatory internet filtering scheme are lining up to applaud its demise.

Yandex launches public DNS service with malicious URL filtering - Internet-based applications and services ...
Russian Web search firm Yandex launched a public DNS (Domain Name System) resolution service on Thursday that leverages the company's existing ...

The Filter Is Dead: Australian Government Dumps Controversial Filtering Project [Updated]
Almost three years ago now, Senator Stephen Conroy stepped up to the plate to deliver a bold new vision. A vision of a filtered, “safer” i... ...

Resources last updated: 12/28/2015 10:07:38 PM