惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - Eric Fine

Wii Party U 游戏简介 OracleParameter.UdtTypeName的值必须是全大写! VS2012调用64位IIS Express [Fix] Emulator Error: Could not load OpenGLES emulation library: Could not load DLL! [Fix] "Loading toolbox content from package Microsoft.VisualStudio.IDE.Toolbox.ControlInstaller.ToolboxInstallerPackage'{2C98B35-07DA-45F1-96A3-BE55D91C8D7A}'" 暗黑3 API 预览版 中兴光纤猫 F420 破解 [Fix] Blend 4 出现 Line:0 Position:0 错误 多维数组操作 诺基亚WP7手机 710/800一分钟完美越狱测试 三星WP7手机MANGO一分钟完美越狱 Silverlight 4 Binding Cheatsheet [转] 让WCF代替WSE访问需要明文UserName/Password验证的WebService 變形金剛塔防 Anti-TD Xeno Tactic 2 Medieval Rampage Mac OS X Leopard 10.5.5 安裝手记 (Dell D830) 将DataTable导出为Excel (XML Spreadsheet).
SPGridView 研究笔记 Part 3 - 分组
Eric Fine · 2008-10-23 · via 博客园 - Eric Fine

SPGridView提供数据分组显示功能, 但是只能将页面内数据分组. 只要设置 AllowGrouping(true), GroupField(某列名) 就能实现下面的效果.P3-3

如果需要给分组的列加链接加菜单的话, 就得再设置GroupMenu. GroupMenu需要一个SPMenuField对象, 而SPMenuField又需要一个MenuTemplate.

所以我们先加入一个MenuTemplate.

<cc1:MenuTemplate ID="mtCategory" runat="server">
    <cc1:MenuItemTemplate ID="mitFilter" runat="server" Text="View Products" />
</cc1:MenuTemplate>

由于这个GroupMenu不在Columns里, 而SPMenuField又不能像MenuTemplate一样扔在SPGridView之外. 所以只好在代码里加了.

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    this.SPGridView1.GroupMenu = new SPMenuField();
    this.SPGridView1.GroupMenu.MenuTemplateId = this.mtCategory.ID;
    this.SPGridView1.GroupMenu.HeaderText = "Category";
    this.SPGridView1.GroupMenu.TextFields = "CategoryName";
}

现在来看看效果吧.

P3-1 P3-2

完整代码:

<%@ Page Language="C#" MasterPageFile="~masterurl/Default.Master" %>

<%@ Register Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebControls" TagPrefix="cc1" %>

<script runat="server">
   1:  
   2:     protected override void OnInit(EventArgs e)
   3:     {
   4:         base.OnInit(e);
   5:         this.SPGridView1.GroupMenu = new SPMenuField();
   6:         this.SPGridView1.GroupMenu.MenuTemplateId = this.mtCategory.ID;
   7:         this.SPGridView1.GroupMenu.HeaderText = "Category";
   8:         this.SPGridView1.GroupMenu.TextFields = "CategoryName";
   9:     }
</script> <asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server"> </asp:Content> <asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server"> SPGridView Demo: Part 3 - Grouping </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" runat="server"> <!--SPGridView--> <cc1:SPGridView ID="SPGridView1" runat="server" EnableViewState="false" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1" AllowSorting="true" AllowGrouping="true" GroupField="CategoryName" AllowGroupCollapse="true"> <Columns> <cc1:SPBoundField DataField="ProductId" HeaderText="Product ID" SortExpression="ProductId"> </cc1:SPBoundField> <cc1:SPBoundField DataField="ProductName" HeaderText="Product Name" SortExpression="ProductName" /> <asp:BoundField DataField="UnitPrice" DataFormatString="${0:F2}" HeaderText="Unit Price" SortExpression="UnitPrice" /> <asp:TemplateField HeaderText="Orderable" SortExpression="Discontinued"> <itemtemplate> <asp:Label id="lblDiscontinued" runat="server" text='<%# Convert.ToBoolean(Eval("Discontinued")) ? "Yes" : "No" %>'></asp:Label> </itemtemplate> </asp:TemplateField> </Columns> </cc1:SPGridView> <!--SPGridView--> <!--MenuTemplate--> <cc1:MenuTemplate ID="mtCategory" runat="server"> <cc1:MenuItemTemplate ID="mitFilter" runat="server" Text="View Products" /> </cc1:MenuTemplate> <!--MenuTemplate--> <!--ObjectDataSource--> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetProductList" TypeName="SPGridView_Demo.NorthwindData" SortParameterName="sortExpression"></asp:ObjectDataSource> <!--ObjectDataSource--> </asp:Content>

特别注意:
  1.启用分组后, 如果不把EnableViewState设置为false, 排序功能就会出错. 寒~~
  2.启用分组后, 过滤功能会失灵. 晕倒~~
  3.如果使用了ObjectDataSource来分页数据, 那么分组只能分当前页的, 过滤功能也失灵. 汗~~