Chaks' Corner

SharePoint and other stuffs

4. June 2009 12:04
by Chakkaradeep
0 Comments

Using same custom edit forms across different Lists in SharePoint

4. June 2009 12:04 by Chakkaradeep | 0 Comments

We have a customer who has 5 different Lists and all the Lists have same content type associated with it. They wanted a custom edit form for this content type and want to use it across those 5 different Lists to enter data. We created the custom edit form very easily and uploaded the form to the Layouts folder (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS) so that we can load it in the code-behind.

The problem arose when we wanted to use the same custom edit form across different List as these custom edit forms are bound to a specific List

<ParameterBindings>
            <ParameterBinding Name="ListItemId" Location="QueryString(ID)" DefaultValue="0"/>
            <ParameterBinding Name="ListID" Location="None" 
                     DefaultValue="{7A0F7220-4967-4061-985D-D78F4435B071}"/>
            <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
            <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
            <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
</ParameterBindings>

 

As you can see in the above snippet, it is clearly bound to a List with ID {7A0F7220-4967-4061-985D-D78F4435B071}

So, how can you associate this custom edit form to work across a different List? I don't want to create x-number of forms for x-number of Lists!

Well, out of luck, we actually figured it out how to do so! – Setting the DefaultValue of the ListID to 0

If you put 0 instead of the List ID, it automagically identifies the List that the form is bound to during runtime and works like a charm!

So, here is my XML schema after the change:

<ParameterBindings>
            <ParameterBinding Name="ListItemId" Location="QueryString(ID)" DefaultValue="0"/>
            <ParameterBinding Name="ListID" Location="None" DefaultValue="0"/>
            <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
            <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
            <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
</ParameterBindings>

Its weird, but true :)

Comments are closed