2009-05-21 59 views
1

我想創建一個自定義字段類型,它將顯示基於同一列表中的另一個字段的值。 (基本上,根據源列的值顯示一些圖像)自定義字段類型派生自SPFieldCalculated

由於此列完全基於另一列導出其數據,因此我需要確保列值不存儲在數據庫中。

所以,我想我需要創建一個派生自SPFieldCalculated類的自定義字段類型。

但是,當我嘗試這樣做,我得到一個錯誤信息 「類型‘Microsoft.SharePoint.SPFieldCalculated’沒有定義構造函數」

如何創建一個自定義字段類不從SPFieldCalculated獲得? 如果這是不可能的,至少有人能告訴我如何滿足我的要求?

回答

2

在fieltype xml中,您可以在模板的CAML中添加LookupColumn。 在你的問題你可以使用字段類型的文本,並在DisplayPattern寫這樣的東西。

<RenderPattern Name="DisplayPattern"> 
    <HTML><![CDATA[<img src="]]></HTML> 
     <LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" /> 
    <HTML><![CDATA["/>]]></HTML> 
</RenderPattern> 
0

恐怕我還沒有嘗試過自定義字段..但是我有一個建議,可能工作。該領域可能只是一個圖片領域。每當目標字段更改時,您可以使用列表中的事件接收器來計算必需字段。一個漫長的迂迴路線,但如果你沒有得到自定義領域的方式工作,這可能。

1

有任何你想要從SPFieldCalculated說的SPField沒有?我將通過創建基於SPField的自定義字段來解決問題,然後我將:

1在字段編輯器中註冊一個事件接收器,並使用它來設置字段的值。

2如果你想預覽編輯/新形式的價值,計算出現場控制值。這要求您的字段在您的價值基礎的字段下方排列,否則您將最終根據舊數據計算您的價值。

我也建議你保存你的計算值,而不是重新計算它。如果您想在列表視圖中顯示數據,這是唯一合理的方式,因爲您在CAML中編寫渲染模式,而不是C#。

1

從列表創建custom view style可能實際上獲得更多里程。

這將允許您完全改變列顯示html方式,而無需添加計算字段。

Alternativley你也可以考慮用schemaxml中的自定義字段定義來做一些非常有趣的事情。作爲一個例子,我在普通的發佈頁面庫中包含了一個「名稱」字段的schema xml。

<Field ID="{9d30f126-ba48-446b-b8f9-83745f322ebe}" ReadOnly="TRUE" Type="Computed" Name="LinkFilenameNoMenu" DisplayName="Name" DisplayNameSrcField="FileLeafRef" Filterable="FALSE" AuthoringInfo="(linked to document)" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="LinkFilenameNoMenu" FromBaseType="TRUE"><FieldRefs><FieldRef Name="FileLeafRef" /><FieldRef Name="FSObjType" /><FieldRef Name="Created_x0020_Date" /><FieldRef Name="FileRef" /><FieldRef Name="File_x0020_Type" /><FieldRef Name="ContentTypeId" /><FieldRef Name="PermMask" /><FieldRef Name="CheckoutUser" /><FieldRef Name="IsCheckedoutToLocal" /></FieldRefs><DisplayPattern><IfEqual><Expr1><LookupColumn Name="FSObjType" /></Expr1><Expr2>1</Expr2><Then><FieldSwitch><Expr><GetVar Name="RecursiveView" /></Expr><Case Value="1"><LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" /></Case><Default><SetVar Name="UnencodedFilterLink"><SetVar Name="RootFolder"><HTML>/</HTML><LookupColumn Name="FileRef" /></SetVar><SetVar Name="FolderCTID"><FieldSwitch><Expr><ListProperty Select="EnableContentTypes" /></Expr><Case Value="1"><Column Name="ContentTypeId" /></Case></FieldSwitch></SetVar><FilterLink Default="" Paged="FALSE" /></SetVar><HTML><![CDATA[<A onfocus="OnLink(this)" HREF="]]></HTML><GetVar Name="UnencodedFilterLink" HTMLEncode="TRUE" /><HTML><![CDATA[" onclick="javascript:EnterFolder(']]></HTML><ScriptQuote NotAddingQuote="TRUE"><GetVar Name="UnencodedFilterLink" /></ScriptQuote><HTML><![CDATA[');return false;">]]></HTML><LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" /><IfEqual><Expr1><GetVar Name="ShowAccessibleIcon" /></Expr1><Expr2>1</Expr2><Then><HTML><![CDATA[<img src="/_layouts/images/blank.gif" class="ms-hidden" border=0 width=1 height=1 alt="]]></HTML><HTML>Use SHIFT+ENTER to open the menu (new window).</HTML><HTML><![CDATA[">]]></HTML></Then></IfEqual><HTML><![CDATA[</A>]]></HTML></Default></FieldSwitch></Then><Else><HTML><![CDATA[<A onfocus="OnLink(this)" HREF="]]></HTML><Field Name="ServerUrl" URLEncodeAsURL="TRUE" /><HTML><![CDATA[" onclick="return DispEx(this,event,']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTransform" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTrAcceptType"><Column Name="File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTrHandleUrl"><Column Name="File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTrProgId"><Column Name="File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ListProperty Select="DefaultItemOpen" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><MapToControl><Column Name="HTML_x0020_File_x0020_Type" /><HTML>|</HTML><Column Name="File_x0020_Type" /></MapToControl></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Column Name="HTML_x0020_File_x0020_Type" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="GetServerFileRedirect"><Field Name="ServerUrl" /><HTML>|</HTML><Column Name="HTML_x0020_File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Column Name="CheckoutUser" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><UserID AllowAnonymous="TRUE" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ListProperty Select="ForceCheckout" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Field Name="IsCheckedoutToLocal" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Field Name="PermMask" /></ScriptQuote><HTML><![CDATA[')">]]></HTML><UrlBaseName HTMLEncode="TRUE"><LookupColumn Name="FileLeafRef" /></UrlBaseName><IfEqual><Expr1><GetVar Name="ShowAccessibleIcon" /></Expr1><Expr2>1</Expr2><Then><HTML><![CDATA[<img src="/_layouts/images/blank.gif" class="ms-hidden" border=0 width=1 height=1 alt="]]></HTML><HTML>Use SHIFT+ENTER to open the menu (new window).</HTML><HTML><![CDATA[">]]></HTML></Then></IfEqual><HTML><![CDATA[</A>]]></HTML><IfNew Name="Created_x0020_Date"><HTML><![CDATA[<IMG SRC="/_layouts/1033/images/new.gif" alt="]]></HTML><HTML>New</HTML><HTML><![CDATA[">]]></HTML></IfNew></Else></IfEqual></DisplayPattern></Field> 

令人討厭但有力。

2

遺憾的是它不能夠從SPCalculatedField類,這就是爲什麼你將收到一個錯誤繼承: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldcalculated.aspx

Windows SharePoint Services 3.0 does not support inheriting from this class.

爲了顯示基於另一列的值的圖像2007你將不得不在fldtypes中做一些不愉快的CAML工作... xml(As @David A提到)。這裏有一個良好的開端: http://msdn.microsoft.com/en-us/library/aa544291.aspx

我還要傻傻地提到,有可能是使用這一功能的商業選擇,其中之一可能我幫助創建,並可能已在這裏提到: Sharepoint webpart for conditional formatting?

相關問題