Sharepoint 2010 使用SPGridView时出现分页错误
我正在使用与SPGridView关联的OOTB SPGridViewPager控件。这在2007年运行良好,但现在我们已经升级到2010年,我在尝试翻阅数据集时遇到以下错误: System.InvalidCastException:无法将类型为“System.Int32”的对象强制转换为类型为“System.String”。在Microsoft.SharePoint.WebControl.SPGridView.set_PageIndex(Int32值)在Microsoft.SharePoint.WebControl.SPGridViewPager.OnClickNext(EventArgs args)在Microsoft.SharePoint.WebControl.SPGridViewPager.RaisePostBackEvent(String EventArgum)在System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)位于System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔IncludeStagesSafetaSyncpointSharepoint 2010 使用SPGridView时出现分页错误,sharepoint-2010,Sharepoint 2010,我正在使用与SPGridView关联的OOTB SPGridViewPager控件。这在2007年运行良好,但现在我们已经升级到2010年,我在尝试翻阅数据集时遇到以下错误: System.InvalidCastException:无法将类型为“System.Int32”的对象强制转换为类型为“System.String”。在Microsoft.SharePoint.WebControl.SPGridView.set_PageIndex(Int32值)在Microsoft.SharePoint.
我的代码仍然引用版本12 Microsoft.SharePoint程序集,因此我不太确定是什么更改导致了此问题。此处存在相同的问题。但是,我没有使用
SPGridViewPager
控件。我只是调用.PageIndex=e.NewPageIndex;
这两个都是整数类型。我正在中进行赋值>PageIndexchange(对象发送方,GridViewPageEventArgs e)
方法
不确定这一点上发生了什么。我现在正在反射器中观察这一点
我想知道你是否在使用数据键?看起来这里发生了两次强制转换。请参见下面
public override void set_PageIndex(int value)
{
int pageIndex = this.PageIndex;
DataKeyArray dataKeys = this.DataKeys;
base.PageIndex = value;
if (pageIndex != this.PageIndex)
{
this.PreviousPageIndex = pageIndex;
if ((dataKeys == null) || (dataKeys.Count <= 0))
{
this.PreviousPageFirstRowDataKey = null;
this.PreviousPageLastRowDataKey = null;
}
else
{
**this.PreviousPageFirstRowDataKey = (string) dataKeys[0].Value;
this.PreviousPageLastRowDataKey = (string) dataKeys[dataKeys.Count - 1].Value;**
}
}
}
public override void set\u页面索引(int值)
{
int pageIndex=this.pageIndex;
DataKeyArray dataKeys=this.dataKeys;
base.PageIndex=值;
if(pageIndex!=此.pageIndex)
{
this.PreviousPageIndex=页面索引;
如果((dataKeys==null)| |(dataKeys.Count哇,这似乎是SPGridViewPager中的一个bug。我刚刚遇到了同样的问题,将我的数据键类型从int改为string解决了这个问题。谢谢你的评论,它真的帮助了我!谢谢你,这救了我一命!不过这是一个相当愚蠢的bug。