我有一个继承自SPFieldMultiColumn
的自定义共享点字段。该字段的值如下所示:
“;#column one value; #column two 值; #column三值;#“
我想在单独的一行中显示每个项目并删除
;#
我查看了这个链接http://msdn.microsoft.com/en-us/library/ms411957(office.12).aspx 并发现这可以通过覆盖字段的渲染模式来实现,如此
<RenderPattern Name="DisplayPattern" DisplayName="DisplayPattern">
<Switch>
<Expr>
<GetVar Name="FreeForm"/>
</Expr>
<Case Value="TRUE">
<Column/>
</Case>
<Default>
<HTML>
<![CDATA[ <DIV ALIGN=RIGHT> ]]>
</HTML>
<Column/>
<HTML>
<![CDATA[ </DIV> ]]>
</HTML>
</Default>
</Switch>
</RenderPattern>
这需要预先定义SubColumns的数量,在我的情况下它可以是任意数字。
所以我需要一个for循环遍历我的多列字段中的每个子列?
怎么办呢? 感谢
答案 0 :(得分:1)
米娜,
我在帮助你的时候用光了,这里是我的Xml和相关课程标题的全部内容供你参考,祝你好运。
<?xml version="1.0" encoding="utf-8"?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">CountryStateCityAddress1Field</Field>
<Field Name="TypeDisplayName">CountryStateCityAddress1Field</Field>
<Field Name="TypeShortDescription">CountryStateCityAddress1Field</Field>
<Field Name="ParentType">MultiColumn</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="FieldTypeClass">c0d4e972-cae4-4320-b13b-83ed0bf8cedc</Field>
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr>
<Column />
</Expr>
<Case Value="" />
<Default>
<Column SubColumnNumber="0" HTMLEncode="TRUE" />
<HTML><![CDATA[<br/>]]></HTML>
<Column SubColumnNumber="1" HTMLEncode="TRUE" />
<HTML><![CDATA[<br/>]]></HTML>
<Column SubColumnNumber="2" HTMLEncode="TRUE" />
<HTML><![CDATA[<br/>]]></HTML>
</Default>
</Switch>
</RenderPattern>
</FieldType>
<FieldType>
<Field Name="TypeName">EMailFieldTypeField</Field>
<Field Name="TypeDisplayName">EMailFieldTypeField</Field>
<Field Name="TypeShortDescription">EMailFieldTypeField</Field>
<Field Name="ParentType">MultiColumn</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="FieldTypeClass">0e8a370a-0388-4b78-9e5c-ffbb8a481391</Field>
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr>
<Column />
</Expr>
<Case Value="" />
<Default>
<Column SubColumnNumber="0" HTMLEncode="TRUE" />
<HTML><![CDATA[<br/>]]></HTML>
<Column SubColumnNumber="1" HTMLEncode="TRUE" />
<HTML><![CDATA[<br/>]]></HTML>
<Column SubColumnNumber="2" HTMLEncode="TRUE" />
<HTML><![CDATA[<br/>]]></HTML>
</Default>
</Switch>
</RenderPattern>
</FieldType>
</FieldTypes>
接头:
namespace CustomFieldTypeAddress1
{
[CLSCompliant(false)]
[Guid("0e8a370a-0388-4b78-9e5c-ffbb8a481391")]
public class EMailFieldTypeField : SPFieldMultiColumn
...
namespace CustomFieldTypeAddress1
{
[CLSCompliant(false)]
[Guid("dc20d765-2d36-4396-83aa-f063166d8fcc")]
public class EMailFieldTypeFieldControl : BaseFieldControl
...
答案 1 :(得分:0)
答案 2 :(得分:0)
我遇到的问题是由Xml文件中的ParentType引起的
在修复之前:
<Field Name="ParentType">Text</Field>"
修好后:
<Field Name="ParentType">MultiColumn</Field>"
答案 3 :(得分:0)
whan SPFieldMultiColumn
对象使用方法override BaseFieldControl FieldRenderingControl
它加载从BaseFieldControl
继承的对象,
因此,继承BaseFieldControl
的对象有一个调用
protected override void RenderFieldForDisplay(HtmlTextWriter output){}
在此方法中,您可以渲染适合您的控件。
您可以使用以下示例
namespace SharePointTestApplication
{
public class UserChoiceColumn:SPFieldMultiColumn
{
public UserChoiceColumn(SPFieldCollection fields, string fname)
: base(fields, fname) { }
public UserChoiceColumn(SPFieldCollection fields, string tname, string dname)
: base(fields, tname, dname) { }
public override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl ctr = new UserChoiceColumnControlType();
ctr.FieldName = this.InternalName;
return ctr;
}
}
public override string GetFieldValueAsHtml(object value)
{
SPFieldMultiColumnValue mcv = new SPFieldMultiColumnValue(value.ToString());
return string.Format("{0} , {1}",mcv[0],mcv[1]);
}
}
public class UserChoiceColumnControlType : BaseFieldControl
{
#region Protected Members
protected TextBox TextBox1;
protected TextBox TextBox2;
#endregion
protected override string DefaultTemplateName
{
get
{
return "UserChoiceColumnTemplate";
}
}
protected override void CreateChildControls()
{
base.CreateChildControls();
TextBox1 = (TextBox)this.TemplateContainer.FindControl("TextBox1");
TextBox2 = (TextBox)this.TemplateContainer.FindControl("TextBox2");
}
public override object Value
{
get
{
this.EnsureChildControls();
SPFieldMultiColumnValue mcv = new SPFieldMultiColumnValue(2);
mcv[0] = TextBox1.Text;
mcv[1] = TextBox2.Text;
return mcv;
}
set
{
this.EnsureChildControls();
SPFieldMultiColumnValue mcv = (SPFieldMultiColumnValue)this.ItemFieldValue;
TextBox1.Text = mcv[0];
TextBox2.Text = mcv[1];
}
}
**protected override void RenderFieldForDisplay(HtmlTextWriter output)
{
output.Write("hello world");
// base.RenderFieldForDisplay(output);
}**
}
}