Friday, August 27, 2010

Creating a generic Data Form web part with SharePoint Designer 2010


If you create a List Form web part and save it to a file or gallery you get a prompt whether you want the web part saved with a relative path (list name is stored in the web part) or fixed to thesite (list id is saved in the web part)


If you create a Data Form web part and save it to a file or gallery you do not get this prompt.
Insert > Data View > Empty Data View
Select a Data Source, then insert fields as Single Item Form.
Save Web Part to a gallery.

To make the web part generic and referencing a file name you need to do the following changes.

In the property ParameterBindings replace:
ParameterBinding Name="ListID" Location="None" DefaultValue="{01CF5B35-CB1E-4A5A-82D1-144C6A0312E2}"
with
ParameterBinding Name="ListName" Location="None" DefaultValue="Shared Documents"

Also replace
property name="ListName" type="string">{01CF5B35-CB1E-4A5A-82D1-144C6A0312E2}
with
property name="ListName" type="string">Shared Documents

remove this line
01cf5b35-cb1e-4a5a-82d1-144c6a0312e2

And replace each occurence of
ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{01CF5B35-CB1E-4A5A-82D1-144C6A0312E2}" Name="ListID"
with
ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="Shared Documents" Name="ListName"

Make sure that the ListId and the List Guid do not appear any where else in the webpart.

Now you have a generic Data Form web part!

With thanks to Sandeep and the folks at Trinedy.