场景:我已经通过BCS获得了数据来源,并且表示它始终与BCS开箱即用。我想做的是自定义New和EditForms,以便在我的某个字段中允许DropDown
。
我试过:创建基于SPFieldChoide
的自定义字段(在自定义列表中测试,它运行正常)并通过添加BCS配置XML文件(.bdcm)属性SPCustomFieldType
到我想要定制的字段。
错误:我可以打开ReadItem / NewForm / EditForm页面和自定义字段渲染,但是在打开ReadList页面时会抛出错误
执行Web部件时出错:System.NotSupportedException:对于外部列表,BiConvenioGrupoChoiceField不支持方法'GetFieldAttributeValue'。
在Microsoft.SharePoint.SPExternalList.ThrowNotSupportedExceptionForMethod(String sMethodName,Type typeThrowing)
在Microsoft.SharePoint.SPFieldChoice.get_Sortable()
在Microsoft.SharePoint.SPField.AnnotateField(XmlNode fieldRefNode)
在Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.AddInFieldSchema(XmlNodeList fieldRefNodes,SPList list)
在Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.AddInTypeInfoIntoViewXml(XmlNode viewXml)
在Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.ModifyXsltArgumentList(ArgumentClassWrapper argList)
在Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTransform(Boolean bDeferExecuteTransform)
让我们来看看代码。
自定义字段.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
}
自定义字段控制
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
<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>
答案 0 :(得分:0)
我只是覆盖自定义字段类中的属性Sortable
。
public override bool Sortable
{
get
{
return false;
}
}
像魅力一样。