一个简单的Checkbox Custom Field Type
2008-05-30 17:10
267 查看
这个字段是一个普通的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 == null) return;
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,蓝色的是陈曦那个。
效果图:
下面介绍制作过程:
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 == null) return;
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,蓝色的是陈曦那个。
相关文章推荐
- 一个简单的Checkbox Custom Field Type
- 一个简单的Checkbox Custom Field Type
- wss custom field type
- 向大家请教一个关于sharepoint2003的问题,如何使一个Custom List in Datasheet View中某个field从其他list抽取数据当显示时?
- 一个较简单的js实现checkbox的全选与全不选功能
- HTML基础 form-input中的type属性checkbox 显示一个打钩的多选框框
- SPGridView - Using a custom TemplateField to add a Checkbox Column
- Sharepoint Custom Control Creating custom Multi Choice field type
- 处理ASP中checkbox 在 form enctype="multipart/form-data"中只能取一个的问题
- SharePoint基于SPFieldMultiColumn的Custom Field Type切记要覆盖GetFieldValue方法
- 写了一个简单的带有CheckBox的Tree[Swing]
- MOSS 2007 CMS Project Technical Issues: Custom Field Type
- Create custom field type
- 综合应用WPF/WCF/WF/LINQ之四十:实现一个简单的DataGrid之CheckBox已勾选的项的保存
- How to Add Custom Field Type (in SPFieldType Enum) Programatically or any other way
- 实作一个简单自定义的View(一) -- A Simple Custom View Example (1)
- 解决Custom Field Type修改时属性显示不正确的问题
- 一个简单的checkbox全选实现
- 一个Simple而又SB的问题 @Autowired Field xxxDao in xxx requird a bean of type
- SharePoint Custom Field Type与RenderTemplate ID与ascx页面无关联