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 919原文链接 http://weblogs.asp.net/j ... -
SharePoint Custom Action Identifiers
2011-11-16 13:48 1009原文链接 http://johnholliday.net/ ... -
Filtering with SPGridView
2011-10-12 15:23 771原文链接 http://vspug.com/bobsbon ... -
SPGridView and SPMenuField: Displaying custom data through SharePoint lists
2011-10-11 16:14 1295原文链接 http://blogs.msdn.com/b/ ... -
How to work around bugs in the SPGridView control
2011-10-11 16:10 830原文链接 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 957原文链接 http://www.nearinfinity. ... -
SharePoint – Adding ECB Menu Item for Specific Custom List
2011-10-11 10:52 950原文链接 http://www.csharpest.net ... -
Adding CheckBoxes in SharePoint GridView (SPGridView)
2011-10-10 17:01 969原文链接 http://www.c-sharpcorner ... -
SharePoint的列级安全性
2011-10-10 11:25 1161原文链接 http://www.infoq.com/cn/ ... -
在 SharePoint 中自定义审核
2011-10-09 16:59 1735原文链接 http://msdn.micr ... -
SharePoint 2007 and Windows WorkFlow Foundation: Integrating Divergent Worlds
2011-10-09 16:32 1429原文链接 http://www.developer.com ... -
通过 STSDEV 简化 SharePoint 开发
2011-09-30 15:58 1298原文链接 http://msdn.microsoft.co ... -
计算字段公式
2011-09-30 15:47 899原文链接 http://msdn.microsoft ...
相关推荐
1. **SPGridView**: SPGridView是SharePoint自定义控件库中的一个强大控件,它是ASP.NET GridView的扩展,专为SharePoint设计。SPGridView提供了更方便的方式来绑定SharePoint列表数据,同时具备了内置的排序、分页...
SPGridView是SharePoint环境中一个强大的数据展示控件,它是ASP.NET GridView控件的扩展,专为在SharePoint环境中提供更灵活的数据操作和定制化功能而设计。这个控件允许开发者以高度自定义的方式显示和操作...
SPGridView 是 SharePoint 2007 中的一个控件,它扩展了传统的 ASP.NET GridView 控件的功能,提供了更多用于数据展示和交互的特性。这个控件主要用于在 SharePoint 页面上展示和操作数据,通常是从数据库或其他数据...
- SPGridView 不支持自动生成列,所以需手动创建并设置每列的 `HeaderText`、`DataField` 和 `SortExpression`。 - 开启排序功能:`SPGridView1.AllowSorting = true`。 5. **设置过滤字段** - 使用 `...
SPGridView绑定数据(ObjectDataSource,SPDataSource)实例。 说明ObjectDataSource,SPDataSource作为数据源的有点与缺点。。。 文档为office2010的。。
SPGridView是SharePoint对ASP.NET GridView的扩展,提供了与列表数据交互的更多功能,如与SharePoint列表的集成、权限控制等。开发者可能在这个用户控件中实现了特定的数据展示和操作逻辑。 总之,QuickPart是...
- 使用 `SPGridView` 控件来展示数据,可能包括从 SharePoint 数据源获取的数据。 ##### 3. Exercise 3 - Connecting WebParts - **情景描述**:此练习专注于创建具备连接功能的 WebPart,即一个 WebPart 可以从另...