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

推荐订阅源

L
LangChain Blog
Martin Fowler
Martin Fowler
P
Palo Alto Networks Blog
MongoDB | Blog
MongoDB | Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
博客园_首页
量子位
小众软件
小众软件
F
Full Disclosure
Vercel News
Vercel News
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
博客园 - 聂微东
V
V2EX
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
L
Lohrmann on Cybersecurity
H
Hacker News: Front Page
Spread Privacy
Spread Privacy
AI
AI
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CERT Recently Published Vulnerability Notes
D
Docker
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Recorded Future
Recorded Future
L
LINUX DO - 热门话题
Microsoft Azure Blog
Microsoft Azure Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Latest news
Latest news
W
WeLiveSecurity
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 司徒正美
博客园 - 叶小钗
T
Threat Research - Cisco Blogs
P
Privacy International News Feed
O
OpenAI News
Help Net Security
Help Net Security
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
博客园 - Franky

博客园 - 蒜头

Mailbox unavailable. The server response was: 5.7.1 Unable to relay for (email address). 再谈Images到xps,pdf的转换 SQL Server 2005中xml类型和函数的简单应用 部分Office 2007文件格式转换为xps和pdf代码整理 Image.FromFile gives "Out of Memory" Exception for icon - 蒜头 简单介绍PDF,XPS,Images,Office 2007之间的转换方法 - 蒜头 - 博客园 SQL 2005 全文检索(续) 简单实现C#生成Excel 2007文件并下载 简单应用ReportViewer控件 配置SQL Server Session方法 采用负载均衡,部署了两个ASP.NET 2.0的站点服务器碰到的问题 初试VSTS 2008(TFS安装) Windows Server 2003分区修改方法[转载] 制作VSTO 2005 SE开发的Office 2007 AddIn的安装包 一个简单的document library event handler VS 2005 SP1 安装错误 [续] ASP.NET 2.0 SQL Cache 配置方法 解读Document Library关于权限的对象模型 SharePoint应用AJAX.NET和AJAX Control Toolkit
一个简单的Checkbox Custom Field Type
蒜头 · 2007-08-17 · via 博客园 - 蒜头

这个字段是一个普通的Single line of text,作用就是显示一个Checkbox,checkbox 的value为这个Text字段的值。
效果图:

下面介绍制作过程:

1. 首先,写一个派生自标准Field Type的类,

 1    public class SPCheckboxField : SPFieldText
 2    {
 3        public SPCheckboxField(SPFieldCollection fields, string fieldName)
 4            : base(fields, fieldName)
 5        {
 6        }

 7
 8        public SPCheckboxField(Microsoft.SharePoint.SPFieldCollection fields, string typeName, string displayName)
 9            : base(fields, typeName, displayName)
10        {
11        }

12
13        public override Microsoft.SharePoint.WebControls.BaseFieldControl FieldRenderingControl
14        {
15            get
16            {
17                Microsoft.SharePoint.WebControls.BaseFieldControl checkboxFieldControl = new CheckboxFieldControl();
18                checkboxFieldControl.FieldName = InternalName;
19                return checkboxFieldControl;
20            }

21        }

22    }

2. 写一个UC 命名为CheckboxField.ascx:

1<%@ Control Language="C#" Debug="true" %>
2<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
3<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebControls" %>
4
5<SharePoint:RenderingTemplate ID="CheckboxFieldControl" runat="server">
6    <Template>
7        <asp:TextBox ID="txtUrl" Enabled="false" MaxLength="255" runat="server" Columns="50" />
8    </Template>
9</SharePoint:RenderingTemplate>

3. 写一个对应CheckboxField.ascx 的类:

 1  public class CheckboxFieldControl : BaseFieldControl
 2    {
 3        protected TextBox txtUrl;
 4
 5        protected override string DefaultTemplateName
 6        {
 7            get
 8            {
 9                return "CheckboxFieldControl";
10            }

11        }

12
13        public override object Value
14        {
15            get
16            {
17                EnsureChildControls();
18                return txtUrl.Text.Trim();
19            }

20            set
21            {
22                EnsureChildControls();
23                txtUrl.Text = (string)this.ItemFieldValue;
24            }

25        }

26
27        public override void Focus()
28        {
29            EnsureChildControls();
30            txtUrl.Focus();
31        }

32
33        protected override void CreateChildControls()
34        {
35            if (Field == nullreturn;
36           base.CreateChildControls();
37
38            if (ControlMode == Microsoft.SharePoint.WebControls.SPControlMode.Display)
39                return;
40
41            txtUrl = (TextBox)TemplateContainer.FindControl("txtUrl");
42
43            if (txtUrl == null)
44                throw new ArgumentException("txtUrl is null. Corrupted CheckboxField.ascx file.");
45
46            txtUrl.TabIndex = TabIndex;
47            txtUrl.CssClass = CssClass;
48            txtUrl.ToolTip = Field.Title;
49        }

50    }

4. 写一个xml:
fldtypes_CheckboxField.xml注意名字必须以fldtypes_开头.

 1<?xml version="1.0" encoding="utf-8"?>
 2<FieldTypes>
 3    <FieldType>
 4        <Field Name="TypeName">CheckboxField</Field>
 5        <Field Name="ParentType">Text</Field>
 6        <Field Name="TypeDisplayName">Checkbox Field</Field>
 7        <Field Name="TypeShortDescription">Checkbox Field</Field>
 8        <Field Name="UserCreatable">TRUE</Field>
 9        <Field Name="ShowInListCreate">TRUE</Field>
10        <Field Name="ShowInSurveyCreate">TRUE</Field>
11        <Field Name="ShowInDocumentLibraryCreate">TRUE</Field>
12        <Field Name="ShowInColumnTemplateCreate">TRUE</Field>
13        <Field Name="Sortable">FALSE</Field>
14        <Field Name="AllowBaseTypeRendering">TRUE</Field>
15        <Field Name="Filterable">FALSE</Field>
16        <Field Name="FieldTypeClass">CheckboxCustomField.SPCheckboxField,CheckboxCustomField,Version=1.0.0.0,Culture=neutral,PublicKeyToken=5acbdc949ff711be</Field>
17        <RenderPattern Name="DisplayPattern">
18            <Switch>
19                <Expr>
20                    <Column/>
21                </Expr>
22                <Case Value="">
23                </Case>
24                <Default>
25                    <HTML><![CDATA[<input type='checkbox' name='my_select' value=']]></HTML>
26                    <Column HTMLEncode="TRUE"/>
27                    <HTML><![CDATA[' />]]></HTML>
28                </Default>
29            </Switch>
30        </RenderPattern>
31    </FieldType>
32</FieldTypes>

   都是些配置的信息,最主要显示的部分是这里:

1                    <HTML><![CDATA[<input type='checkbox' name='my_select' value=']]></HTML>
2                    <Column HTMLEncode="TRUE"/>
3                    <HTML><![CDATA[' />]]></HTML>


5. 这样就OK了,开始部署:
    1) 将编译后dll放入GAC
    2) 把UC放到C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES
    3) 把xml放到C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML
    4) 重启IIS

在create column会看到我们的Checkbox Field:

红色的就是这个custom field type,蓝色的是陈曦那个。