自定义FieldRenderingControl Sharepoint 2010
我已在sharepoint项目中创建了一个自定义字段,并且该字段为空,我已覆盖FieldRendering控件,以便在显示列表中的项时创建自己的表布局 我遇到的问题是呈现控件类中的ItemFieldValue始终为null 如何获取要显示的字段的字段值 这是我的自定义字段类自定义FieldRenderingControl Sharepoint 2010,sharepoint,sharepoint-2010,custom-fields,Sharepoint,Sharepoint 2010,Custom Fields,我已在sharepoint项目中创建了一个自定义字段,并且该字段为空,我已覆盖FieldRendering控件,以便在显示列表中的项时创建自己的表布局 我遇到的问题是呈现控件类中的ItemFieldValue始终为null 如何获取要显示的字段的字段值 这是我的自定义字段类 namespace CustomFieldDefinitions.Fields { public class AttributeField : SPField { #region Constr
namespace CustomFieldDefinitions.Fields
{
public class AttributeField : SPField
{
#region Constructors
/// <summary>
/// This is a constuctor with two parameters.
/// </summary>
/// <param name="fields"></param>
/// <param name="fieldName"></param>
public AttributeField(SPFieldCollection fields, string fieldName)
: base(fields, fieldName)
{
}
/// <summary>
/// This is a contructor with three parameters.
/// </summary>
/// <param name="fields"></param>
/// <param name="typeName"></param>
/// <param name="displayName"></param>
public AttributeField(SPFieldCollection fields, string typeName, string displayName)
: base(fields, typeName, displayName)
{
}
#endregion
#region Overridden Properties
/// <summary>
/// This ties the control used to support this field with the current implementation of it.
/// </summary>
public override BaseFieldControl FieldRenderingControl
{
[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
get
{
BaseFieldControl fieldControl = new AttributeFieldControl();
fieldControl.FieldName = this.InternalName;
return fieldControl;
}
}
public override object GetFieldValue(string value)
{
return base.GetFieldValue(value);
}
#endregion
}
}
最后是标记
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" %>
<SharePoint:RenderingTemplate ID="AttributeFieldDisplayControl" runat="server">
<Template>
<asp:Label ID="lblAttValue" runat="server" BorderColor="Red"></asp:Label>
</Template>
</SharePoint:RenderingTemplate>
<SharePoint:RenderingTemplate ID="AttributeFieldControl" runat="server">
<Template>
<asp:TextBox ID="txtAttValue" runat="server" BorderColor="Red"></asp:TextBox>
</Template>
</SharePoint:RenderingTemplate>
随函附上此问题的答案。我是一个巨大的白痴。调用BdcModel的ReadItem方法时,我没有设置传递到显示页面的对象的“AttributeValue”属性
所以有一次我补充说,一切都很好。感谢所有看过这篇文章的人。很抱歉,我浪费了你的时间。我们可以看看你用来做这件事的标记/代码吗?谢谢你看一看,我已经发布了代码和标记。在FieldRenderingControl类中,它当前正在读取ListItemFieldValue,因为我一直在尝试每个属性,但我最初是从ItemFieldValue开始的。发布此消息后,我做了一些事情来尝试使其正常工作。我已经对该字段中显示的数据进行了硬编码,以确保有一个值要传递给显示、编辑和新视图。我还下载了几个正在运行的示例,并将它们与我自己的进行了比较,所有内容都按顺序显示。我只是不明白为什么列表视图中的值没有被传递到显示模式框。我还知道它正在使用我的自定义字段渲染控件,因为当我打开编辑表单时,我得到了一个红色边框的文本框。
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" %>
<SharePoint:RenderingTemplate ID="AttributeFieldDisplayControl" runat="server">
<Template>
<asp:Label ID="lblAttValue" runat="server" BorderColor="Red"></asp:Label>
</Template>
</SharePoint:RenderingTemplate>
<SharePoint:RenderingTemplate ID="AttributeFieldControl" runat="server">
<Template>
<asp:TextBox ID="txtAttValue" runat="server" BorderColor="Red"></asp:TextBox>
</Template>
</SharePoint:RenderingTemplate>