In Part 1: Using SPGridview, adding menus, grouping and sorting I looked at how to use an SPGridView from the ground up to bind to a custom DataSet. One of the features I omitted at the time was paging: Jason Wang already has a good post on the subject, but I’m going to continue my example with some pretty verbose code so hopefully things will just work first time for you. There is a gotcha – in order to display the paging tabs PagerTemplate needs to be set to null after the grid is added to the controls collection but before BindData is called; and you’ll need to give some extra consideration if you’re also using sorting. In Part 3 by the way, I really want to cover filtering, but it’s proving tricky stuff, due to the way SPGridView is designed to process the filtering callback. At least I understand the problem - more on that shortly. Extending your code Pop this code just above oGrid.DataBind(): and add the event handler: Part 2: Extending your SPGridview with paging controls
// Turn on paging and add event handler
oGrid.PageSize = 3;
oGrid.AllowPaging = true;
oGrid.PageIndexChanging +=
new GridViewPageEventHandler(oGrid_PageIndexChanging);
oGrid.PagerTemplate = null; // Must be called after Controls.Add(oGrid)
// Recreate current sort if needed
if (ViewState["SortDirection"] != null && ViewState["SortExpression"] != null)
{
// We have an active sorting, so this need to be preserved
oView.Sort = ViewState["SortExpression"].ToString()
+ " " + ViewState["SortDirection"].ToString();
}
void oGrid_PageIndexChanging(object sender, GridViewPageEventArgs e) { oGrid.PageIndex = e.NewPageIndex; oGrid.DataBind(); }
The extra lines around sorting are important if you enabled sorting on the list in Part 1. Adding the paging means CreateChildControls() could now fire on a postback without a subsequent call to oGrid_Sorting(). Depending on how you’re implementing state, this could mean the list switches back to being unsorted – giving the impression of duplicating or missing out entries if you sort before you page, so to speak.
Enjoy.
发表评论
-
Creating Hierarchical Menus with a CustomAction in SharePoint
2011-11-17 14:11 881原文链接 http://weblogs.asp.net/j ... -
SharePoint Custom Action Identifiers
2011-11-16 13:48 908原文链接 http://johnholliday.net/ ... -
Filtering with SPGridView
2011-10-12 15:23 749原文链接 http://vspug.com/bobsbon ... -
SPGridView and SPMenuField: Displaying custom data through SharePoint lists
2011-10-11 16:14 1267原文链接 http://blogs.msdn.com/b/ ... -
How to work around bugs in the SPGridView control
2011-10-11 16:10 787原文链接 http://blogs.msdn.com/b/ ... -
How to add a custom action to a SharePoint list actions menu for a specific list
2011-10-11 10:56 925原文链接 http://www.nearinfinity. ... -
SharePoint – Adding ECB Menu Item for Specific Custom List
2011-10-11 10:52 899原文链接 http://www.csharpest.net ... -
Adding CheckBoxes in SharePoint GridView (SPGridView)
2011-10-10 17:01 916原文链接 http://www.c-sharpcorner ... -
SharePoint的列级安全性
2011-10-10 11:25 1128原文链接 http://www.infoq.com/cn/ ... -
在 SharePoint 中自定义审核
2011-10-09 16:59 1690原文链接 http://msdn.micr ... -
SharePoint 2007 and Windows WorkFlow Foundation: Integrating Divergent Worlds
2011-10-09 16:32 1381原文链接 http://www.developer.com ... -
通过 STSDEV 简化 SharePoint 开发
2011-09-30 15:58 1236原文链接 http://msdn.microsoft.co ... -
计算字段公式
2011-09-30 15:47 850原文链接 http://msdn.microsoft ...
相关推荐
这是一个简单的利用SPGridView来显示SharePoint列表数据的例子,包括实现排序,过滤,分页。
spgridview 使用方法(带二级功能菜单) 同时附上了使用sharepoint与自定义数据源的代码
SPGridView绑定数据(ObjectDataSource,SPDataSource)实例。 说明ObjectDataSource,SPDataSource作为数据源的有点与缺点。。。 文档为office2010的。。
SPGridView能实现的页面效果,最主要的还是可以绑定数据库。
SPGridView绑定数据(实现分页,排序,过滤,带菜单)。自己的学习心得,与大家分享。