2012-06-08 22 views
0

我已經創建了一個自定義字段和空SharePoint項目,我已經覆蓋了FieldRenderingControl所以顯示在列表中的項目時,我可以創建自己的表格佈局。定製FieldRenderingControl SharePoint 2010的

我遇到的問題是,ItemFieldValue在渲染控制類總是空。

如何獲得該領域我想顯示的字段值?

這是我的自定義字段類

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> 
+0

我們能看到你用來做此標記/代碼? –

+0

感謝您的關注,我發佈了代碼和標記。在FieldRenderingControl類中,它當前正在讀取ListItemFieldValue,因爲我一直在嘗試每個屬性,但我最初是使用ItemFieldValue開始的。 – Maxmanzero

+0

自發布以來,我已經做了一些嘗試並使其正常工作。我已硬編碼要顯示在此字段中的數據,以確保有值傳遞給顯示,編輯和新視圖。我還下載了幾個正在工作的例子,並將它們與我自己的例子進行比較,並且所有內容都按順序排列。我只是不明白爲什麼列表視圖中的值沒有傳遞給顯示模式框。 – Maxmanzero

回答

1

隨函附上的回答這個問題。我是一個巨大的白癡。當我的BdcModel的ReadItem方法被調用時,我沒有設置傳遞給顯示頁面的對象的'AttributeValue'屬性。

所以一旦我補充說,一切工作就好了。感謝任何看過這篇文章的人。我很抱歉我浪費了你的時間。