1

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.

Thanks

2 Answers 2

1

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

public class MySPGridView : SPGridView
{
    public void ClearFilter()
    {
        base.RaisePostBackEvent("__SPGridView__;__Filter__;__ClearFilter__");
    }
}
2
  • Thanks,good idea. How will this technique work?, is it going to clear the filter every time a post back occurs?. Commented Feb 14, 2012 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
    Commented Feb 15, 2012 at 8:44
0

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.

1
  • 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. Commented Feb 13, 2012 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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