0

空の sharepoint プロジェクトにカスタム フィールドを作成し、FieldRenderingControl をオーバーライドして、リスト内の項目が表示されたときに独自のテーブル レイアウトを作成できるようにしました。

私が抱えている問題は、レンダリング コントロール クラスの ItemFieldValue が常に null であることです。

表示しようとしているフィールドのフィールド値を取得するにはどうすればよいですか?

これは私のカスタムフィールドクラスです

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

    }
}

そして、私の FieldRenderingControl クラス

namespace CustomFieldDefinitions.FieldControls
{
    public class AttributeFieldControl : BaseFieldControl
    {
        protected Label AttributeValueForDisplay;
        protected TextBox AttributeValueTextbox;

        public override string DisplayTemplateName
        {
            get
            {
                 return "AttributeFieldDisplayControl";
            }
            set
            {
                base.DisplayTemplateName = value;
            }
        }

        protected override string DefaultTemplateName
        {
            get
            {
                 if (this.ControlMode == SPControlMode.Display)
                {
                    return this.DisplayTemplateName;
                }
                else
                {
                    return "AttributeFieldControl";
                }
            }
        }

        protected override void CreateChildControls()
        {
            if (this.Field != null)
            {
                 base.CreateChildControls();

                 this.AttributeValueForDisplay = (Label)TemplateContainer.FindControl("lblAttValue");
                 this.AttributeValueTextbox = (TextBox)TemplateContainer.FindControl("txtAttValue");

                 if (ControlMode == SPControlMode.New || ControlMode == SPControlMode.Edit)
                 {
                     AttributeValueTextbox.Text = Convert.ToString(this.ListItemFieldValue);
                 }
                 else
                 {
                     AttributeValueForDisplay.Text = Convert.ToString(this.ListItemFieldValue);
                 }
            }
        }
    }
}

そして最後にマークアップ

<%@ 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>
4

1 に答える 1

1

この質問に対する回答を同封してください。私は巨大なバカです。BdcModel の ReadItem メソッドが呼び出されたときに、表示ページに渡されるオブジェクトの 'AttributeValue' プロパティを設定していませんでした。

そのため、すべてが正常に機能していることを追加しました。この投稿を見てくれた人に感謝します。お時間を無駄にしてしまい申し訳ありません。

于 2012-06-11T18:10:02.993 に答える