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'm using the SPGridView in a custom page which has been deployed via SharePoint Designer. Now in 2007 everything worked fine but in 2010, the paging doesn't work and results in an error if you try and page to the next page so my question is;

When using custom code compiled for 2007 assemblies, does SharePoint use the 2007 controls (SPGridView) or does it perform some sort of redirect and try and use the 2010 controls? It's the only explanation I can think of that could be causing problems.

For info, the error I get when using the SPGridViewPager control is;

System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'. at Microsoft.SharePoint.WebControls.SPGridView.set_PageIndex(Int32 value) at Microsoft.SharePoint.WebControls.SPGridViewPager.OnClickNext(EventArgs args) at Microsoft.SharePoint.WebControls.SPGridViewPager.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint

share|improve this question

Existing code that utilizes object model and runs within IIS will continue to work without recompilation (if compiled for AnyCPU or 64-bit).

As when upgrading from SPS 2003 to SharePoint 2007 the upgrade process inserts assembly binding redirects from old assemblies to new assemblies (here to making the code automatically redirect to the new SharePoint dll’s.

Code that runs outside IIS and utilizes the object model (workflows, feature receivers, timer jobs etc.) will either need recompilation or binding redirects to work with SP2010.

You can also utilize this in your own solutions, so you can now utilize assembly versioning when coding to SharePoint (this was a painpoint in earlier versions)

<Solution …>
        <Assembly DeploymentTarget=”GlobalAssemblyCache” Location=”MyWebPart.dll”>
                <BindingRedirect OldVersion=”” NewVersion=”” />
share|improve this answer
The code runs within IIS and within SharePoint context and other than the paging issue works fine, weird. – Anonymous Aug 3 '10 at 18:37
you could compare the two implementations (12 vs 14) in Reflector and see if changes were made or if you can track down the reason for the issue – Anders Rask Aug 4 '10 at 10:16
up vote 2 down vote accepted

It was the DataKeyNames property that was causing the issue. When I removed that paging worked as expected.

share|improve this answer

Are you able to recompile the code and reference the SP2010 assemblies? I think that'd be your recommended route.

share|improve this answer
Doh! Never thought of that. Will give that a try at work tomorrow. – Anonymous Aug 3 '10 at 18:37
Ok, compiled it for version 14 assemblies but still no change. It compiled ok and ran as before but still the same issue. – Anonymous Aug 4 '10 at 7:58
as i said above, binding redirects take care of the assembly redirection, so it shouldnt make any difference if inside IIS – Anders Rask Aug 4 '10 at 10:14
So it must be related to it using 2010 assemblies. Using Reflector I noticed that the 2007 SPGridView doesn't have a PageIndex property so obviously inherits from the ASP.NET GridView class. Whereas the 2010 SPGridView does have it's own PageIndex property. Not sure if that's relevant or not. – Anonymous Aug 4 '10 at 13:20

Your Answer


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