Change the Presentation of Fields in SharePoint 2010 External Lists 


As Business Connectivity Solutions gain more traction, I increasingly see people trying to change the way fields are displayed in External Lists. Common complaints include the fact that Date fields always include time, or that fields presented as text should be choices. Still others want to use URL information to display an image.
Unfortunately, the OOB External List does not provide much built-in capability to render these special fields. The good news, however, is that there are several ways to solve the problem. Here is a list of approaches from simple to complex. I cover each of these in detail in my book Professional Business Connectivity Services.
Create Views and Stored Procedures in the Database
If the External System is a database, then you can use a database view or stored procedure to format data before it is returned. For example, you can convert Data fields to text and remove the time. External Lists display dates as text OOB, so you aren't loosing anything with this approach except the unwanted time information.
Create custom InfoPath or ASPX forms
Just like standard lists, External Lists support custom InfoPath and ASPX forms. InfoPath forms can use controls to completely change the user interface and add validation logic. ASPX forms support XSLT, which can be used to change URL fields into images.
Use XSLT and the External Data web parts
External Data web parts accept custom XSLT, which can be used in the same way as ASPX forms.
Use a FormatString property or RedererDefinition
In cases where fields can easily be converted to formatted text, use a FormatString property in the BDC Metadata Model to define how the field should be formatted. For complete control, a RendererDefinition property can reference a custom rendering class to create the formatted field. The following code shows a sample:

       <TypeDescriptor Name="BusinessAddress"

        TypeName="ComplexTypeConnector.Address, ComplexCustomerModel"



        <Property Name="FormatString" Type="System.String">

         {0}, {1}, {2} {3}




        <TypeDescriptor Name="Street" TypeName="System.String" />

        <TypeDescriptor Name="City" TypeName="System.String" />

        <TypeDescriptor Name="State" TypeName="System.String" />

        <TypeDescriptor Name="Zip" TypeName="System.String" />



Create a custom web part
You can take complete control over the rendering of an External List by writing a custom web part that calls the BDC Server Runtime API. The BDC Server Runtime API will return data from the External System, which can then be rendered in controls like an SPGridView.
Create custom field types/field controls
External Lists can use custom field types/field controls to render fields. Create the field types and field controls as normal and then associate them with fields in the BDC Metadata Model. The following code shows a sample:

       <TypeDescriptor TypeName="System.Int64" Name="LegacyMainframeID">


         <Property Name="SPCustomFieldType" Type="System.String">





Create a .NET Assembly Connector
When you create a .NET Assembly Connector, you control how the connections and operations are performed on the External System. You can also control how the data is formatted and returned to SharePoint. This allows you to format fields before they are returned and renderd in the External List.
Posted by Scot Hillier on 20-Sep-10
0 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        

Links to this post