Filtering in SPGridView
hello i'm trying to implement filtering in SPGridView with SPDataSource as the source data.
when i click the filter feature it throws
"SPGridView_FilterCallbackErrorHandler() result = Object reference not set to an instance of an object"

somehow i cannot get any documentation for SPGridView_FilterCallbackErrorHandler() in msdn or google.
can someone help me thks.

this is part of my code in page_load

SPDataSource mySPDS = new SPDataSource();

SPSite siteCollection = SPContext.Current.Site;
SPWeb site = siteCollection.OpenWeb();
SPBoundField BField = new SPBoundField();
BField.DataField = "Title";
BField.HeaderText = "EmployeeNumber";
grdPropertyValues.AllowSorting = true;
SPBoundField BField1 = new SPBoundField();
BField1.HeaderText = "EmployeeName";
BField1.DataField = "EmployeeName";
SPBoundField Bfield2 = new SPBoundField();
Bfield2.HeaderText = "EmployeeUserId";
Bfield2.DataField = "EmployeeUserId";
mySPDS.List = SPContext.Current.Web.Lists["TestList"];
grdPropertyValues.AllowGrouping = false;
grdPropertyValues.AllowGroupCollapse = false;
grdPropertyValues.GroupField = "Title";
grdPropertyValues.GroupDescriptionField = "Title";
grdPropertyValues.GroupFieldDisplayName = "Programme";

grdPropertyValues.DataSource = mySPDS;

grdPropertyValues.FilteredDataSourcePropertyName = "FilterExpression";
grdPropertyValues.FilterDataFields = "Title";
grdPropertyValues.FilteredDataSourcePropertyFormat = "{1} LIKE '{0}'";
grdPropertyValues.AllowSorting = true;
grdPropertyValues.AllowFiltering = true;


January 20th, 2009 4:32am

You FilterDataFields only contains Title are you trying to filter on another column?


Free Windows Admin Tool Kit Click here and download it now
January 20th, 2009 10:14am

I have exactly the same problem and would be very interested by any solution you might have found.
By the way, on this code, I thing the DataBind method call should be moved in the PreRender ou Render method.
June 17th, 2009 10:19pm

Can you check this article, This may help you.

Free Windows Admin Tool Kit Click here and download it now
June 17th, 2009 11:00pm

I've seen it. The problem is I always get stuck with the NullReferenceException.
The AJAX request launched when I open the filter menu of any header menu just returns "eObject reference not set to an instance of an object".
June 18th, 2009 7:30am

Can you post your code?
Free Windows Admin Tool Kit Click here and download it now
June 18th, 2009 8:17pm

Well, in fact I found the solution. The problem was coming from a bad WebControl life cycle management.
The reason is that I needed to give the DataSource in the CreateChildControls, before or in the OnPreRender was too late.
  • Proposed as answer by John Guilbert Saturday, July 24, 2010 7:02 PM
June 18th, 2009 8:22pm

Hi Florent,

I've tried implementing filtering using visual webpart, and i'm facing the same problem as you are. 


My spgridview:

oGridView.AllowFiltering = true;

oGridView.FilterDataFields = "Name,Description,Price,QtyInStock,Value";

oGridView.FilteredDataSourcePropertyName = "FilterExpression";

oGridView.FilteredDataSourcePropertyFormat = "{1} LIKE '{0}'";


I'm using an IList<Business objects> as datasource with 4 SPBoundField and 1 SPMenuField


I keep getting object reference not set to an instance error...

Free Windows Admin Tool Kit Click here and download it now
June 3rd, 2010 10:04am

Hi Gary,

I am in the exact same position as you were, 3 years later. Have you been able to solve this issue?? Thanks for any help!

February 20th, 2014 9:16am


Did u get any help for this problem?

Free Windows Admin Tool Kit Click here and download it now
June 11th, 2015 1:08am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics