Thursday, July 31, 2008

DataForm WebPart [escape from hardcoded List GUIDs]

SharePoint Designer is undoubtedly, an impeccable tool when it comes to quick and dirty UI creation. Quick drag and drop approach of Lists/Libraries allow easy readable access at UI level. However it has certain limitations. For say, we created a new page and added new DataForm webpart using drag and drop in our development environment. Once our development is complete, it is required to move changes to staging environment. So, as a developer I have numerous options to achieve this by using feature deployment, wsp deployment or simply move aspx page to target Site Collection. Doing so, I see my page containing DataForm webpart does not work.

This is due to the fact that, by default, SharePointDesigner binds the control to the list instance using the list instance GUID. To resolve this we need to replace the GUIDs by the list name. The steps to do this are:
1) On the attributes of the DataFormWebPart element replace the attribute ListName="{GUID}" by ListName="LIST_NAME" where LIST_NAME is the name of the list that you are binding to.

2) Go through all of the DataFormParameter elements and replace:

<WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{GUID}"/>

With:

<WebPartPages:DataFormParameter Name="ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="LIST_NAME"/>

3) Go to the ParameterBindings element and replace

<ParameterBinding Name="ListID" Location="None" DefaultValue="{GUID}"/>

With:

<ParameterBinding Name="ListName" Location="None" DefaultValue="LIST_NAME"/>

This should give you a GUID free DataForm webpart that can be placed on a page layout used by multiple sites on your site collection (as long as the name of the list is the same on all sites).

Cheers

3 comments:

Anonymous said...

I tried this and all was fine except the ParameterBinding section which required a guid to bind to a list.

Anonymous said...

ok sorry the stuff about parameter binding i came out with yesterday is wrong i was not changing the ListID to ListName

Steve B. said...

Useful post... I've lost some hours trying to set up the listID from my feature...

this is much simple :)