Problem with DisplayPattern in SharePoint 2010

sharepoint-2010spfieldspfieldcollection

I am adding a new field to a list using the AddFieldAsXML method of SPFieldCollection. The method executes fine with no problem. And the column header shows up when I view the list; however the value never displays in the column. Here is what the field looks like after it has been added to the list. This xml is a snipped from the list schema derived using http://tw-s1-m4400-007:4016/_vti_bin/owssvr.dll?Cmd=ExportList&List={1F87433F-50E1-46C5-A138-00E1CF7E5801}

This code works great in 2007 but does not work in 2010. Any help would be appreciated.

<Field ID="{e24ccb96-35fd-44e5-b7d1-4150dbbc9a64}" Type="Computed" ReadOnly="TRUE"
   Name="My_x0020_Status" DisplayName="MyStatus" ShowInEditForm="TRUE" ClassInfo="Icon"   
AuthoringInfo="(My status)" SourceID="http://schemas.microsoft.com/sharepoint/v3"       
StaticName="MyStatus" FromBaseType="TRUE">  
 <FieldRefs>
  <FieldRef Name="ID" /> 
  <FieldRef Name="Title" /> 
 </FieldRefs>
 <DisplayPattern>
 <HTML>
 <![CDATA[ <a href="form.htm?ID="
  ]]> 
  </HTML>
  <Column Name="ID" /> 
 <HTML>
 <![CDATA[ ">
  ]]> 
  </HTML>
  <Column Name="Title" /> 
 <HTML>
 <![CDATA[ </a>
  ]]> 
  </HTML>
  </DisplayPattern>
</Field>

Best Answer

This link provided a lot of help in solving this issue:

http://social.technet.microsoft.com/Forums/en/sharepoint2010customization/thread/ef0d1d22-47ff-416c-becd-13d48de80e4d

Basically, display patterns fields are defined in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\XSL\fldtypes.xsl file.

There is a file called fldtypes_ratings.xsl that you can use as an example of defining your custom field display.

You can create your own xsl file (i.e. fldtypes_myfile.xsl) to define your own custom display.

Here's a sample of my content:

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" 
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-
prefixes="xsl msxsl ddwrt" ns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:asp="http://schemas.microsoft.com/ASPNET/20" 
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">

<xsl:template match="FieldRef[@Name='MyCustomField']" mode="Computed_body">
    <xsl:param name="thisNode" select="."/>
      <SPAN class="mystuff-content-item" style="Width:100%;text-align:center">
          <SPAN class='mystuff-socialized-status mystuff-socialized-status-unknown'></SPAN>
          <SPAN class="mystuff-content-object-type" style="display:none">
               MyContent
          </SPAN>
          <SPAN class="mystuff-content-followed" style="display:none">0</SPAN>
          <SPAN class="mystuff-content-name" style="display:none"></SPAN>
          <SPAN class="mystuff-content-id" style="display:none">
            <xsl:value-of select="$List" />
            <xsl:text>|</xsl:text>
            <xsl:value-of select="$thisNode/@ID" />
          </SPAN>
      </SPAN>
    </xsl:template>

</xsl:stylesheet>

Hope that helps!

Related Topic