tags:

views:

30

answers:

2

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 move 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.

A: 

The SPGridView is contained in the Microsoft.SharePoint.dll assembly (Microsoft.SharePoint.WebControls namespace).

Which version of the Microsoft.SharePoint.dll is installed on your server? If you are using a server with 2010 installed, you should read this MSDN post on how to redeploy customizations that were built for 2007 in 2010.

I strongly recommend that you don't try to use a different version of the SharePoint.dll just for that control, you will end up with a mess. Just build your code for 2010 using the article that I linked to and your paging should work fine.

Hugo Migneron
The server has been upgraded to SharePoint 2010. I've recompiled my project for the version 14 assemblies and re-deployed that but the same problem still exists.
sparkymark75
Then your code should be using the 2010 SPGridView and you can't really make it use the 2007 one. Does your SPGridView work in your development environment? What kind of error are you getting? A javascript error or an exception or something else?
Hugo Migneron
The error 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
sparkymark75
I notice 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.
sparkymark75
Well you are getting that error because you are setting the page number using a string instead of an int. Look in your code for something like grid.PageIndex = "1"; instead of grid.PageIndex = 1;
Hugo Migneron
Is it not the opposite, it's trying to cast an integer as a string?The problem is, I'm not setting the PageIndex property in code. I have an SPGridView declartively setup on a page in SPD along with an SPGridViewPager. All out of the box.
sparkymark75
Yes it is, my bad. I can't really help you with SharePoint Designer as i've never used it. You are using the 2010 version I assume?
Hugo Migneron
Yeah I am, thanks for the help anyhow. Not realy much to go wrong in SPD, just like designing an ASP.NET page declaratively.
sparkymark75
A: 

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

sparkymark75