How to establish a parent – child relationship in SharePoint

I want to show you one of the ways how to quickly establish parent – child relationship in SharePoint. By using this way you will be able to add child items on the parent item view page as shown in the image below:
091709_0840_Howtoestabl1

The idea how to add new child item form is borrowed from OOTB SharePoint Blog application template. By investigating how comments are implemented on Post.aspx page I was able to reuse OOTB SharePoint:SubmitCommentButton control which is used by BlogCommentsForm SharePoint:RenderingTemplate. BlogCommentsForm rendering template is defined in Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES\DefaultTemplates.ascx file. So here are quick steps how to achieve this:

  1. First you need a parent and child lists. In my example I have Orders and Oder details lists. In child list you need to create a lookup column to parent list named PostTitle (you must use this name because this is the name of column which is used by OOTB SubmitCommentButton functionality). It is important to choose ID column in the “In this column” combo box. You can hide PostTitle lookup column if you want.
  2. Now using SharePoint Designer 2007 open your site and navigate to the parent list folder. Copy DispForm.aspx and rename the copy CustomDispForm.aspx (you can choose whatever name you want).
  3. In the CustomDispForm.aspx replace ListFormWebPart with DataFormWebPart.
  4. Add new ListFormWebPart for the new child list item form. Choose New item form in List or Document Form dialog.
  5. Add child list Web Part for displaying all child list items.
  6. Set CustomDispForm.aspx to be the parent list default display form.
  7. In the DefaultTemplates.ascx find SharePoint:RenderingTemplate with ID=”BlogCommentsForm”. Select and copy all SharePoint:RenderingTemplate tag.
  8. Create new file SubmitNewProduct.ascx and paste the code you copied in step 7 (you can choose another file name).
  9. Find SharePoint:SubmitCommentButton tag and modify Text attribute to whatever you want (in my example I will use “Add Product”). Save the file in the same directory as DefaultTemplates.ascx.
  10. Using SharePoint Designer 2007 open CustomDispForm.aspx created in step 2. Find ListFormWebPart added in step 4. Change TemplateName tag to a name you named the file in step 8.
  11. Now when you open Order (parent list item) you already can add new child items. But last web part on page still displaying not filtered child items list. All you need to do is Edit the page and modify last web part by setting the following filter: PostTitle is equal to [ID].

In the next post I show how to implement a child item selection from another list. If you noticed in the image above Order details item have a lookup column name Product. By selecting Product automatically are filled child item fields. In others solutions it may be enough to have just a lookup column, but in my case I need to fix product details (name, price and etc.) at the time of Order or Invoice creation because later on product price may change.

Leave a comment

39 Comments.

  1. Help with "TemplateName"

    I’ve tried walking through you example on a demo site and can’t get it to work properly. The “SubmitNewProduct” template is not loading. I’m new to SharePoint development, so I guess I’m overlooking something. In step 10, you said change “TemplateName” tag to a name you named the file in step 8. However, when I add a new ListFormWebPart (in step 4), there is no templateName tag on the webpart. I’ve tried adding the tag but can’t seem to get it work. Can you elaborate on step 10? Perhaps a code snippet of the TemplateName tag and where to place it?

  2. I missed one step. In SubmitNewProduct.ascx file you must change ID to “SubmitNewProduct” also:
    SharePoint:RenderingTemplate ID=”SubmitNewProduct”

    In step 10 you must look for this tag:

    <TemplateName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm"&gt; ListForm</TemplateName>

    and change ListForm to SubmitNewProduct.

    P.S. Sometimes you need to save, close and reopen your page in SharePoint Designer to see full ListFormWebPart code.

  3. Thanks for the quick reply. You were correct in having to close and re-open SP Designer to see the full ListFormWebPart code. I still can’t get the template to load. If I change the template name to “BlogCommentsForm”, the template loads and everything works. However, when i change the template name to SubmitInvoiceProduct, nothing loads. I’ve tried the following to simplify things.

    Copied the BlogCommentsForm template and pasted it at the bottom of the “DefaultTemplates” control. changed the ID to <SharePoint:RenderingTemplate ID="SubmitNewProduct" , changed the template name to SubmitNewProduct, saved and reloaded the page. Template does not load. Do i need to restart IIS or SharePoint services to refresh the templates or load it into the GAC?

    Also, you said to change ID (in SubmitNewProduct.ascx) to SubmitNewProduct. I'm not sure what ID you're refering to. I only have the <SharePoint:RenderingTemplate ID. What other code needs to be included int the template (SubmitNewProduct.ascx)?

    Thanks for the help. If I get this working properly it will open up some options for developing forms with wss 3.0. (we don't have info path on the client machines in our company).

  4. Try reset IIS.

    I’m talking about RenderingTemplate ID:

    <SharePoint:RenderingTemplate ID="SubmitInvoiceProduct" runat="server">

    Beside that you don’t need to change anything in ascx file.

    I see in your last comment that you are using SubmitNewProduct everywhere so TemplateName also must be set to SubmitNewProduct not SubmitInvoiceProduct. In other words TemplateName must be the same as RenderingTemplate ID. (this means that there is one more bug in my 10th step where i said that TemplateName must be set to the file name)

  5. Finally got this working. The issues I had were

    1.) Did not see all the markup for the list created in step 4 until I closed and reopened the custom display form. I was then able to modify the TemplateName.

    2.) I had to restart IIS for the changes to take effect.

    3.) After all of this, SharePoint Designer decided to remove the “~/” from the src attribute on my control templates (including the DefaultTemplates.asxc control) which broke the entire Intranet.

    In short, I am not a fan of SharePoint Designer.

    thanks for the excellent post and the help troubleshooting.

  6. I cannot get the filter to work, PostTitle is equal to [ID]

  7. In step 1 it is important to choose ID column in the “In this column” combo box. That means your PostTitle column must be set to show ID field of related list item.

  8. I did select ID as the lookup for the PostTitle column. The PostTitle even shows the correct ID number, but when I add the filter to the webpart itdoesn’t show any items.

  9. Maybe we can arrage a quick TeamViewer session or similar so i can take a look?

  10. Sorry, could you explain in step 4. I’m new in SharePoint 2007

  11. In SharePoint Designer Insert menu choose SharePoint Controls->List Form. Don’t forget to select child list.

  12. after adding DataFormWebPart, when i view the “customdispform.aspx” in IE, i am getting error “An error occurred processing the data view. The XslText property is empty.”

  13. This is a total hack and really bad instructions, took me 4 hours to understand this and it still doesn’t work correctly as per your instructions!

    I think i’ll go the .net route

  14. Can you do this by code?

    Hello
    this is good, but can you do this by code? using VSeWSS1.3,

  15. Cannot link PostTitle

    Hi,

    Thanks for this post. Saved me alot of time!

    However, i still encounter 1 problem. I cant seem to link the PostTitle to the ID. When I do link it, nothing displays when adding a product. It usually displays PostTitle = “[ID]“. I’ve even tried [ListID] (which is an available selection), @ID, etc. etc.

    Any ideas?

    Thanks. Regards.

    • Hello, I have the same problem, ¿can you resolve this problem?, I try to resolve using XSLT, and JavaScript, not work.

      Thanks.

  16. Cannot link PostTitle

    By the way, the previous post refers to Step 10.

    Thanks.

  17. Re: How to establish a parent – child relationship in SharePoint

    Anyone? i.e. Previous post?

  18. Late response

    Did you ckecked this:

    “TemplateName must be the same as RenderingTemplate ID. (this means that there is one more bug in my 10th step where i said that TemplateName must be set to the file name)”

  19. Re: Later response

    Hi, thanks for the reply.

    Actually, what i’ve done it, instead of creating a new file, i just refernced the ListForm to BlogCommentsForm.

    Basically, I’m using the same Default*.acsx file. I didnt create a new 1.

  20. Re: Later response

    Glad to know you made it :)

  21. How can i get the name of the List when i get to the RenderingTemplate and send it to my WS?
    i succeded to send parameters to my ws function,but does not know how to get the list name or the url that called RenderingTemplate .

  22. Sorry can’t understand what you are asking. What do you mean by “send it to my WS” ?

  23. in MOSS works fine, but in WSS only “unexpected error” after submit action.

  24. Regard WSS error

    It should work on both WSS and MOSS, sorry but from information you provided it is hard to suggest a solution for you problem.

  25. Hi,

    i was trying to follow all the steps, even the suggestions included in the comments. but i cannot overcome the error in Step 3. i cannot change ListFormWebPart with DataFormWebPart cause i cannot save the CustomDisplayForm afterwards. the error message is
    Server Error. The URL is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current web

  26. Hi,

    I cannot get it to work, made a new ascx file:

    &lt;SharePoint:RenderingTemplate ID=&quot;NewPayoutRequest&quot; runat=&quot;server&quot;&gt;
    &lt;Template&gt;
    &lt;table width=275 cellpadding=0 cellspacing=0 border=0&gt;&lt;tr&gt;&lt;td&gt;
    &lt;SPAN id='part1'&gt;
    &lt;SharePoint:InformationBar runat=&quot;server&quot;/&gt;
    &lt;TABLE class=&quot;ms-formtable&quot; border=0 cellpadding=0 cellspacing=0 width=100%&gt;
    &lt;SharePoint:ChangeContentType runat=&quot;server&quot;/&gt;
    &lt;SharePoint:FolderFormFields runat=&quot;server&quot;/&gt;
    &lt;SharePoint:ListFieldIterator runat=&quot;server&quot; ExcludeFields=&quot;PostTitle&quot;/&gt;
    &lt;SharePoint:ApprovalStatus runat=&quot;server&quot;/&gt;
    &lt;SharePoint:FormComponent TemplateName=&quot;AttachmentRows&quot; runat=&quot;server&quot;/&gt;
    &lt;/TABLE&gt;
    &lt;TABLE cellpadding=0 cellspacing=0 width=100% style=&quot;padding-top: 10px&quot;&gt;&lt;tr&gt;&lt;td width=100%&gt;
    &lt;wssuc:ToolBar CssClass=&quot;ms-formtoolbar&quot; id=&quot;toolBarTbl&quot; RightButtonSeparator=&quot;&amp;nbsp;&quot; runat=&quot;server&quot;&gt;
    &lt;Template_RightButtons&gt;
    &lt;SharePoint:SubmitCommentButton CssClass=&quot;ms-ButtonHeightWidth2&quot; runat=&quot;server&quot; Text=&quot;Add New&quot;/&gt;
    &lt;/Template_RightButtons&gt;
    &lt;/wssuc:ToolBar&gt;
    &lt;SharePoint:InitContentType runat=&quot;server&quot;/&gt;
    &lt;SharePoint:ItemHiddenVersion runat=&quot;server&quot;/&gt;
    &lt;/td&gt;&lt;/tr&gt;&lt;/TABLE&gt;
    &lt;/SPAN&gt;
    &lt;/tr&gt;&lt;/td&gt;&lt;/table&gt;
    &lt;SharePoint:AttachmentUpload runat=&quot;server&quot;/&gt;
    &lt;/div&gt;
    &lt;/Template&gt;
    &lt;/SharePoint:RenderingTemplate&gt;

    And if i change the:

    &lt;TemplateName xmlns=&quot;http://schemas.microsoft.com/WebPart/v2/ListForm&quot;&gt;ListForm&lt;/TemplateName&gt;

    The input entry is gone from CustomDispForm.aspx

    Getting this in the eventlog..

    Load control template file /_controltemplates/NewPayoutRequest.ascx failed: Unknown server tag ‘SharePoint:RenderingTemplate’.

    What am i missing ?

    /F

  27. Regard STEP 8 error

    Try adding this at the top of you custom control (ascx) file:

    &lt;%@ Control Language=&quot;C#&quot; %&gt;
    &lt;%@Assembly Name=&quot;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %&gt;
    &lt;%@Register TagPrefix=&quot;SharePoint&quot; Assembly=&quot;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; namespace=&quot;Microsoft.SharePoint.WebControls&quot;%&gt;
    &lt;%@ Register TagPrefix=&quot;wssuc&quot; TagName=&quot;ToolBar&quot; src=&quot;/_controltemplates/ToolBar.ascx&quot; %&gt;
    &lt;%@ Register TagPrefix=&quot;wssuc&quot; TagName=&quot;ToolBarButton&quot; src=&quot;/_controltemplates/ToolBarButton.ascx&quot; %&gt;

    Those code lines is taken from the top of DefaultTemplates.ascx
    (it may be different on your computer).

  28. Regards STEP 3 error

    I googled little bit and found that it can be related to a not closed tag or even missing some tags. Check this out : http://social.msdn.microsoft.com/forums/en-US/sharepointcustomization/thread/4bab44a1-e907-4f18-b165-1e8b4a25883b

  29. Clear Fields after 'Add Product'

    Hi this is awesome !

    Have a question: How can i get it to clear numeric fields after i press ‘Add product’ ? (It clears text fields but not numeric or currency)

  30. Re: How to establish a parent – child relationship in SharePoint

    Question for Step 3:

    How do you replace ListFormWebPart with DataFormWebPart?

  31. Just as an fyi. I have found one small inconvenience when BDC fields are used.

    After submitting the modified form the BDC field is not refreshed or cleared for the next entry.

    Have you seen this?

  32. Hello how can i get ubmitNewProduct.ascx page. and what is OOTB SharePoint Blog application template.

    Please suggest me ….

  33. Hello how can i get submitNewProduct.ascx page. and what is OOTB SharePoint Blog application template.

    Please suggest me ….

  34. Hi,

    i cant understand 11th step..See i cant add any filters..Please sort out this prob..

    Thanks

  35. friends pls refer this below link

    chick here

  36. Hi,

    Is it possible to achieve the same functionality using Javascript (JQuery also) and Sharepoint designer instaed of using user control?

    Since I don’t have server control, I need to achieve the result using site & designer.

    Please suggest me

    Thanks
    Gomathy

  37. Could you please rewrite the post with some images because it is too hard to understand your post?

  38. Hi Guys,

    This is great, thanks for posting this solution, I already implemented this to one of my sharepoint lists. My only issue is that when i added items for my child list it would
    trigger the save and stop editing, can you please guide me on how to remove the save and stop editing. thanks in advance. :D

Leave a Reply

Your email address will not be published. Required fields are marked *

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please copy the string 7irBB3 to the field below: