SharePoint 2007/2010 的"SPGridView "控件常见的两个问题
2010-12-17 11:11
465 查看
问题一:无法显示分页的页码。
很多朋友很奇怪明明已经设置如下的代码
oGrid.AllowPaging = true;
oGrid.PageSize = 2;
oGrid.PageIndexChanging +=new GridViewPageEventHandler(oGrid_PageIndexChanging);
但是页面上无法显示页码。
这个是SharePoint 自己的问题,我们需要加入下面一行代码
Controls.Add(oGrid);
oGrid.PagerTemplate = null;//这行就是要加的代码,顺序很重要,一定要在Controls.Add之后,DataBind();之前
oGrid.DataBind();
现在再试试,是不是就可以看见页码了^_^
问题二:启用了过滤后,在翻页以后,发现在选择下一页,SPGridView会加载所有的数据,而不是filter过滤的数据。过滤功能失效了。
因为在render 下一页后,无法继续保存filter .所以这里有这样一个办法大家可以试试:
首先在OnPreRender里插入下面代码保存FilterExpression 到ViewState中,(记得确保代码里Enable ViewState)
protected override void OnPreRender(EventArgs e) {
ViewState["FilterExpression"] = odsDataSource.FilterExpression;
base.OnPreRender(e);
}
然后
在您的Controls.Add(odsDataSource); 之前插入下面的代码,
HttpRequest req = HttpContext.Current.Request; if (req.Form["__CALLBACKID"] == null ||
req.Form["__CALLBACKPARAM"] == null ||
!req.Form["__CALLBACKID"].EndsWith("ExampleGrid"))
{
if (ViewState["FilterExpression"] != null)
odsDataSource.FilterExpression = (string)ViewState["FilterExpression"];
}
很多朋友很奇怪明明已经设置如下的代码
oGrid.AllowPaging = true;
oGrid.PageSize = 2;
oGrid.PageIndexChanging +=new GridViewPageEventHandler(oGrid_PageIndexChanging);
但是页面上无法显示页码。
这个是SharePoint 自己的问题,我们需要加入下面一行代码
Controls.Add(oGrid);
oGrid.PagerTemplate = null;//这行就是要加的代码,顺序很重要,一定要在Controls.Add之后,DataBind();之前
oGrid.DataBind();
现在再试试,是不是就可以看见页码了^_^
问题二:启用了过滤后,在翻页以后,发现在选择下一页,SPGridView会加载所有的数据,而不是filter过滤的数据。过滤功能失效了。
因为在render 下一页后,无法继续保存filter .所以这里有这样一个办法大家可以试试:
首先在OnPreRender里插入下面代码保存FilterExpression 到ViewState中,(记得确保代码里Enable ViewState)
protected override void OnPreRender(EventArgs e) {
ViewState["FilterExpression"] = odsDataSource.FilterExpression;
base.OnPreRender(e);
}
然后
在您的Controls.Add(odsDataSource); 之前插入下面的代码,
HttpRequest req = HttpContext.Current.Request; if (req.Form["__CALLBACKID"] == null ||
req.Form["__CALLBACKPARAM"] == null ||
!req.Form["__CALLBACKID"].EndsWith("ExampleGrid"))
{
if (ViewState["FilterExpression"] != null)
odsDataSource.FilterExpression = (string)ViewState["FilterExpression"];
}
相关文章推荐
- SharePoint 2007/2010 的"SPGridView "控件常见的两个问题
- "SurfaceView控件"-出现的问题记录
- 使用dsoframer控件出现"Unable to display the inactive document. Click here to reactivate the document."的问题
- OUTLOOK 2007/2010常见问题
- SharePoint 2007 Edit in Datasheet时遇到"The selected cells are read-only."问题
- 独立安装SharePoint 2013碰到的"SDDL"问题及解决方法
- iOS常见问题之 "_kUTTagClassFilenameExtension", referenced from:
- visual studio 2010 "创建控件时出错"解决办法[转]
- 解决Excel 2007的"有 XML 错误的 /xl/sharedStrings.xml"问题 (“发现不可读取的内容,是否回复此工作薄的内容...")
- "SharePoint 14"的正式名称是:Microsoft SharePoint Server 2010
- "SharePoint 14"的正式名称是:Microsoft SharePoint Server 2010
- SharePoint 2007安装后的常见问题
- 基于SharePoint 2010的控制台应用程序常见问题
- SharePoint 2007 "Select People and Groups"中搜索不到其他Domain账户的问题[已解决]
- 解决SharePoint 2013/2010 people picker控件找不到跨域用户的问题
- sharepoint 2010 关于sharepoint时间格式常见问题汇总
- SharePoint 2007工作流开发点滴(5) : "启动时失败"的查错方法
- SharePoint 2010 Console Application 常见问题
- 解决在SharePoint 2010/2013部署自己的Event Handler后,抛出”不能加载被引用的第三方的程序集"的问题
- 使用dsoframer控件出现"Unable to display the inactive document. Click here to reactivate the document."的问题 .