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

推荐订阅源

G
GRAHAM CLULEY
T
Tenable Blog
Know Your Adversary
Know Your Adversary
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Privacy International News Feed
S
Security Affairs
NISL@THU
NISL@THU
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Schneier on Security
Schneier on Security
S
SegmentFault 最新的问题
S
Schneier on Security
G
Google Developers Blog
V
V2EX
C
Check Point Blog
U
Unit 42
Google DeepMind News
Google DeepMind News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
S
Secure Thoughts
博客园 - 司徒正美
Recorded Future
Recorded Future
P
Proofpoint News Feed
Spread Privacy
Spread Privacy
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
AI
AI
博客园 - 聂微东
N
News and Events Feed by Topic
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
P
Palo Alto Networks Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
Recent Commits to openclaw:main
Recent Commits to openclaw:main
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
Project Zero
Project Zero
W
WeLiveSecurity
博客园 - Franky

博客园 - Vengen

【笔记】DataTable或IList使用GroupBy方法的lamda表达式 WSS学习笔记(2) - 用QuickPart部署“用户控件”来替代WebPart WSS学习笔记(1) - 创建简单的WebPart 用ILmerge工具将C#中的EXE和DLL文件合并成单个文件 修改WordPress文章索引列表的日期格式 Windows7部署Android开发环境傻瓜式教程(Eclipse+ADT) 如何使用C#访问WordPress的xmlrpc.php - Vengen - 博客园 Windows7部署WordPress傻瓜式教程(IIS7.5+MySQL+PHP+WordPress) C#面向对象设计模式学习笔记(10) - Facade 外观模式(结构型模式) C#面向对象设计模式学习笔记(9) - Decorator 装饰模式(结构型模式) C#面向对象设计模式学习笔记(8) - Composite 组合模式(结构型模式) C#面向对象设计模式学习笔记(7) - Bridge 桥接模式(结构型模式) C#面向对象设计模式学习笔记(6) - Adapter 适配器模式(结构型模式) C#面向对象设计模式学习笔记(5) - Prototype 原型模式(创建型模式) C#面向对象设计模式学习笔记(4) - Factory Method 工厂方法模式(创建型模式) C#面向对象设计模式学习笔记(3) - Builder 生成器模式(创建型模式) C#面向对象设计模式学习笔记(2) - Abstract Factory 抽象工厂模式(创建型模式) - Vengen C#面向对象设计模式学习笔记(1) - Singleton 单件模式(创建型模式) C#面向对象设计模式学习笔记 - 开篇
WSS学习笔记(3) – 在“用户控件”中使用SPGridView
Vengen · 2011-01-04 · via 博客园 - Vengen

SPGridView是从GridView继承下来的,所以也可以在用户控件中使用它。

1、创建类库 SimpleSPGridView

image

2、创建用户控件 SPGridView.ascx

image

3、在工具栏中添加 SPGridView 和 SPGridViewPager 并拖到ascx页面中。

 image

4、SPGridView是不支持自动生成数据列的,将 SPGridView 的 AutoGenerateColumns 设置为 False ,将 SPGridViewPager 的 GridViewId 指向 SPGridView,并添加 ClickNext 事件

image

5、

ASCX页面:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SPGridView.ascx.cs"
    Inherits="SimpleSPGridView.SPGridView" %>
<%@ Register Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
    Namespace="Microsoft.SharePoint.WebControls" TagPrefix="SharePoint" %>
<SharePoint:SPGridView ID="SPGridView1" runat="server" AutoGenerateColumns="False">
</SharePoint:SPGridView>
<SharePoint:SPGridViewPager ID="SPGridViewPager1" runat="server" GridViewId="SPGridView1"
    OnClickNext="SPGridViewPager1_ClickNext" OnClickPrevious="SPGridViewPager1_ClickPrevious">
</SharePoint:SPGridViewPager> 

CS代码:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts; 

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls; 

namespace SimpleSPGridView
{
    public partial class SPGridView : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SPDataSource ds = new SPDataSource();
            ds.ID = "SimpleDataSource";
            Controls.Add(ds); 

            SPWeb web = SPControl.GetContextWeb(Context);
            SPList list = web.Lists["SimpleList"];
            ds.List = list; 

            SPGridView1.AutoGenerateColumns = false;
            SPGridView1.EnableViewState = false; 

            //添加字段
            SPBoundField col = new SPBoundField();
            col.DataField = "ColID";
            col.SortExpression = "ColID";
            col.HeaderText = "ColID";
            SPGridView1.Columns.Add(col); 

            col = new SPBoundField();
            col.DataField = "ColName";
            col.SortExpression = "ColName";
            col.HeaderText = "ColName";
            SPGridView1.Columns.Add(col); 

            col = new SPBoundField();
            col.DataField = "ColDate";
            col.SortExpression = "ColDate";
            col.HeaderText = "ColDate";
            SPGridView1.Columns.Add(col); 

            SPGridView1.AllowPaging = true;
            SPGridView1.AllowSorting = true; 

            //设置分组
            SPGridView1.AllowGrouping = true;
            SPGridView1.AllowGroupCollapse = true;
            SPGridView1.GroupField = "ColName";
            SPGridView1.GroupFieldDisplayName = "分组"; 

            //绑定数据源
            SPGridView1.PageSize = 3;
            SPGridView1.DataSourceID = "SimpleDataSource";
            SPGridView1.DataBind();
        } 

        protected void SPGridViewPager1_ClickNext(object sender, EventArgs e)
        {
            SPGridView1.DataSourceID = "SimpleDataSource";
            SPGridView1.DataBind();
        } 

        protected void SPGridViewPager1_ClickPrevious(object sender, EventArgs e)
        { 

        } 

    }
} 

用户控件创建完成,现在创建一个测试列表 SimpleList

1、新建自定义列表

image

2、添加三个栏

image

ColID 单行文本

ColName 单行文本

ColDate 日期和时间

image

3、创建一些测试数据

image

按照上一节中的方法,用QuickPart部署该用户控件,结果显示如下图:

image

Vengen

2011-01-04