[英]Custom Field SharePoint BCS Edit and NewForm
Scenario : I've got a source of data coming in through BCS and is represented like it's always represented out of the box with BCS. 场景 :我有一个通过BCS传入的数据源,它的表示方式总是与BCS一起使用。 I would like to do is to customize the New and EditForms to allow a
DropDown
in one of my fields. 我想做的是自定义New和EditForms以允许在我的一个字段中进行
DropDown
。
I've tried : Creating a custom field based on SPFieldChoide
(tested in a custom list and it works just fine) and through the BCS config XML file (.bdcm) added the property SPCustomFieldType
to the field I want to get customized. 我试过了 :创建一个基于
SPFieldChoide
的自定义字段(在自定义列表中进行测试,并且效果很好),并通过BCS配置XML文件(.bdcm)将属性SPCustomFieldType
添加到我要自定义的字段中。
Error: I can open ReadItem/NewForm/EditForm pages and custom field renders just fine yet it throws an error while opening the ReadList page 错误:我可以打开ReadItem / NewForm / EditForm页面,并且自定义字段呈现得很好,但是在打开ReadList页面时会引发错误
Error while executing web part: System.NotSupportedException: Method 'GetFieldAttributeValue' is not supported on BiConvenioGrupoChoiceField for external lists.
执行Web部件时出错:System.NotSupportedException:BiConvenioGrupoChoiceField上的外部列表不支持方法'GetFieldAttributeValue'。
at Microsoft.SharePoint.SPExternalList.ThrowNotSupportedExceptionForMethod(String sMethodName, Type typeThrowing)在Microsoft.SharePoint.SPExternalList.ThrowNotSupportedExceptionForMethod(String sMethodName,type typeThrowing)
at Microsoft.SharePoint.SPFieldChoice.get_Sortable()在Microsoft.SharePoint.SPFieldChoice.get_Sortable()
at Microsoft.SharePoint.SPField.AnnotateField(XmlNode fieldRefNode)在Microsoft.SharePoint.SPField.AnnotateField(XmlNode fieldRefNode)
at Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.AddInFieldSchema(XmlNodeList fieldRefNodes, SPList list)在Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.AddInFieldSchema(XmlNodeList fieldRefNodes,SPList列表)
at Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.AddInTypeInfoIntoViewXml(XmlNode viewXml)在Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.AddInTypeInfoIntoViewXml(XmlNode viewXml)
at Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.ModifyXsltArgumentList(ArgumentClassWrapper argList)在Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.ModifyXsltArgumentList(ArgumentClassWrapper argList)
at Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTransform(Boolean bDeferExecuteTransform)在Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTransform(Boolean bDeferExecuteTransform)
Let's walk through the code. 让我们来看一下代码。
Custom field .cs 自定义字段.cs
class BiConvenioGrupoChoiceField : SPFieldChoice
{
#region Constructors
public BiConvenioGrupoChoiceField(SPFieldCollection fields, string fieldName) : base(fields, fieldName) { }
public BiConvenioGrupoChoiceField(SPFieldCollection fields, string typeName, string displayName) : base(fields, typeName, displayName) { }
#endregion
#region Properties
public override string TypeDisplayName
{
get
{
return "BiConvenioGrupoChoiceField";
}
}
public override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl fieldControl = new BiConvenioGrupoChoiceFieldControl();
fieldControl.FieldName = InternalName;
return fieldControl;
}
}
#endregion
}
Custom field Control 自定义字段控制
class BiConvenioGrupoChoiceFieldControl : BaseFieldControl
{
DropDownList customDropDown;
protected override string DefaultTemplateName
{
get
{
return "DropDownRenderingTemplate";
}
}
protected override void CreateChildControls()
{
try
{
base.CreateChildControls();
customDropDown = (DropDownList)TemplateContainer.FindControl("customDropDown");
if (customDropDown != null)
{
customDropDown.ID = this.FieldName;
if (this.ControlMode == SPControlMode.New || this.ControlMode == SPControlMode.Edit)
{
customDropDown.Items.Add(new ListItem("Option 0", "0"));
customDropDown.Items.Add(new ListItem("Option 1", "1"));
customDropDown.Items.Add(new ListItem("Option 2", "2"));
customDropDown.Items.Add(new ListItem("Option 9", "9"));
}
}
}
catch (Exception ex)
{
SystemLogger.Logger.Log(ex, LoggingLevel.Fatal);
}
}
public override object Value
{
get
{
EnsureChildControls();
return customDropDown.SelectedValue;
}
set
{
this.EnsureChildControls();
customDropDown.SelectedValue = (string)ItemFieldValue;
}
}
}
BCS.bdcm BCS.bdcm
<Method Name="Create">
<Parameters>
<Parameter Name="returnCCCadastrados" Direction="Return">
<TypeDescriptor Name="ReturnCCCadastrados" TypeName="Models.ConvenioBI, CCCadastradosBDC">
<TypeDescriptors>
<TypeDescriptor Name="Dbico_sq" DefaultDisplayName="Id" IdentifierName="Dbico_sq" TypeName="System.Int32" />
<TypeDescriptor Name="Descricao" DefaultDisplayName="Descrição" TypeName="System.String" />
<TypeDescriptor Name="CodigoCorporativo" DefaultDisplayName="Código Corporativo" TypeName="System.String" />
<TypeDescriptor Name="Login" DefaultDisplayName="Criado Por" TypeName="System.String" />
<TypeDescriptor Name="Grupo" DefaultDisplayName="Grupo" TypeName="System.String">
<Properties>
<Property Name="SPCustomFieldType" Type="System.String">BiConvenioGrupoChoiceField</Property>
</Properties>
</TypeDescriptor>
<TypeDescriptor Name="DtCriacao" DefaultDisplayName="Data Criação" IsCollection="false" TypeName="System.DateTime">
<Interpretation>
<NormalizeDateTime LobDateTimeMode="UTC" />
</Interpretation>
</TypeDescriptor>
<TypeDescriptor Name="DtAtualizacao" DefaultDisplayName="Data Atualização" IsCollection="false" TypeName="System.DateTime" >
<Interpretation>
<NormalizeDateTime LobDateTimeMode="UTC" />
</Interpretation>
</TypeDescriptor>
</TypeDescriptors></TypeDescriptor></Parameter>
<Parameter Name="newCCCadastrados" Direction="In">
<TypeDescriptor Name="NewCCCadastrados" TypeName="Models.ConvenioBI, CCCadastradosBDC">
<TypeDescriptors>
<TypeDescriptor Name="Descricao" DefaultDisplayName="Descrição" TypeName="System.String" CreatorField="true" />
<TypeDescriptor Name="CodigoCorporativo" DefaultDisplayName="Código Corporativo" TypeName="System.String" CreatorField="true" />
<TypeDescriptor TypeName="System.String" Name="Grupo" DefaultDisplayName="Grupo" CreatorField="true" >
<Properties>
<Property Name="SPCustomFieldType" Type="System.String">BiConvenioGrupoChoiceField</Property>
</Properties>
</TypeDescriptor>
</TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Name="Create" Type="Creator" ReturnParameterName="returnCCCadastrados" ReturnTypeDescriptorPath="ReturnCCCadastrados" />
</MethodInstances>
</Method>
I just override the property Sortable
in my custom field class. 我只是在自定义字段类中重写属性
Sortable
。
public override bool Sortable
{
get
{
return false;
}
}
Works like charm. 像魅力一样工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.