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

推荐订阅源

T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Palo Alto Networks Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Schneier on Security
Engineering at Meta
Engineering at Meta
I
InfoQ
L
LangChain Blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
WordPress大学
WordPress大学
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Last Watchdog
The Last Watchdog
Last Week in AI
Last Week in AI
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
爱范儿
爱范儿
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
AI
AI
T
Tor Project blog
I
Intezer
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
N
News and Events Feed by Topic
Latest news
Latest news
S
Security Affairs
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
S
Securelist

博客园 - 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来分页数据, 那么分组只能分当前页的, 过滤功能也失灵. 汗~~