SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a textbox a button and a spgridview. When the button is clicked I will search SharePoint with the value in the textbox and bind it to the spgridview. (I'm using LingDataSource). After I filter the spgridview and then click the button again, the new results is still filtered by the previous filter. I tried this

spgvSearchResults.FilterFieldName = string.Empty;

but this will not work since the property is read only.

How do I, upon button click clear any filter on the spgridview if there is any.


share|improve this question
up vote 1 down vote accepted

Create a descendant of SPGridView and add a method to clear the filter.

public class MySPGridView : SPGridView
    public void ClearFilter()
share|improve this answer
Thanks,good idea. How will this technique work?, is it going to clear the filter every time a post back occurs?. – Agamand The True Feb 14 '12 at 2:41
When user clicks "Clear filter" in SPGridView header cell menu, a postback with "SPGridView;__Filter__;__ClearFilter__" parameter is sent. So basically, when you call this method on your button click, you are mimicking user action. Internally the grid will call its SetFilterFieldName and SetFilterFieldValue which will clear the FilterFieldName property. And no, it will not clear the filter every time; it will only clear it if you call the method. – Luc Feb 15 '12 at 8:44
thanks, really appreciate this – Agamand The True Feb 16 '12 at 1:18

About as far as I got on this was clearing out LinqDataSource.Where.

This seemed to reset the grid but it still had the Filter icon in the grid header so I don't think this is what you want.

I'm guessing what you'll have to do is...

  1. Detect when they click the button (probably in the postback button click function)
  2. Remove the grid and datasource from the page's Controls (maybe also in button click function)
  3. Create a new grid and datasource, add to the page

Hopefully someone else has a better solution.

share|improve this answer
I'm assigning the data in the linqdatasource selecting event like this e.Result = GetSeacrhLists();. So the Where is always empty. And also since I'm not creating my control programmatically, removing and adding the controls will introduce more problem. Anyway, thanks for your effort. Hopefully someone out-there have a solution. – Agamand The True Feb 13 '12 at 7:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.