我正在使用与SPGridViewPager关联的OOTB SPGridView控件。这在2007年很好,但现在我们已经升级到2010年,我得到了以下错误时,试图页面浏览数据集;
System.InvalidCastException:无法将'System.Int32‘类型的对象转换为'System.String’。(在Microsoft.SharePoint.WebControls.SPGridView.set_PageIndex(Int32值)在Microsoft.SharePoint.WebControls.SPGridViewPager.OnClickNext(EventArgs args)在Microsoft.SharePoint.WebControls.SPGridViewPager.RaisePostBackEvent(String eventArgument)在System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl ( String eventArgument)在System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,Boolean )
我的代码仍然是指12版本的Microsoft.SharePoint程序集,所以我不太确定是什么改变导致了这个问题。
发布于 2011-01-05 13:38:02
这里也有同样的问题。不过,我不使用SPGridViewPager控件。我只是简单地调用.PageIndex = e.NewPageIndex;,两者都是Integer类型的。我在PageIndexChanging(object sender, GridViewPageEventArgs e)方法中做作业。
不知道这是怎么回事。我现在正在Reflector看这个。
我在想你是不是在用DataKeys?看上去这里有两个模组。见下文。
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;**
}
}
}要解决这个问题,我必须仔细查看我的数据源和数据集。我有一组从Server返回的记录,我所做的是将它们绑定到POCO。该类具有几个Integer类型的公共属性。这些整数是我在网格上的数据。我用一个字符串代替了他们的类型,以绕过铸造问题。
希望这是有意义的。它帮我修好了。
发布于 2012-10-10 17:20:53
哇,看起来这是SPGridViewPager中的一个bug。我刚刚遇到了同样的问题,将数据键类型从int改为string解决了这个问题。谢谢你的评论,它真的帮助了我!
https://stackoverflow.com/questions/3386450
复制相似问题