November 15, 2011

SP2010: Things to check if your Data Form Web Part is misbehaving

Challenge:

You’re working with SharePoint Designer 2010, and trying to add Data Form Web Part to your Page Layout. There are numerous articles explaining how you should change ListID to ListName and everything should be fine.

Well, the DFWP road might sometimes be long, so here are few things I noticed that might save you a few moments especially when trying to make reusable DFWP that would reference to a list always on the site on which the Web Part is sitting in.

Solution:

  1. You must remove attributes related to WebURL if you want to make reusable DFWP
    1. Remove WebURL from WebPartPages:DataFormWebPart > ParameterBinding
      and
      SharePointWebControls:SPDataSource > (Select/Delete/Insert/Modify)Parameters > WebPartPages:DataFormParameter
  2. You can remove SharePointWebControls:SPDataSource > (Delete/Insert/Modify)Parameters if you only use Web Part for showing items
  3. For reusable DFWP you must remove WebPartPages:DataFormWebPart’s attributes called listname and ListID.
  4. For reusable DFWP you must replace ParameterBindings and xsl:params ListID with ListName
    1. Also remember to change the GUID to list name
  5. If your list name contains space character, it’s OK, you can have space character in ListName attribute
  6. NOTE! SharePoint Designer keeps adding some attributes to DFWP even if you don’t use Save. It’s enough if you just close the file and reopen it, the ListName and ListID attributes with GUID values can suddenly be in WebPartPages:DataFormWebPart node.
  7. If it still doesn’t work, remove id and __WebPartId attributes form the WebPartPages:DataFormWebPart tag and let SPD generate them again.
  8. Always keep notepad open and copy paste your working code there
    1. Before copying the working markup to notepad, make sure SPD hasn’t injected ListName and ListID GUID attributes from WebPartPages:DataFormWebPart node
  9. Do not do this:
    1. Edit Page Layout file in SPD window
    2. Save file
    3. Close the Page Layout file window in SPD <<<---- No, no, no!
    4. Check in file in SPD
      --> SPD will insert ListName and ListID attributes into your DFWPs
  10. Do this instead:
    1. Edit Page Layout in SPD window
    2. Save file
    3. In another SPD window in folder view check in your Page Layout file
    4. Close the Page Layout file window

Finally, if you're getting the "List does not exist" error and you're code is exactly how it should be, copy the last working version of DFWP from your backup file. If you compare the working and non-working DFWP's you won't probably notice any differences; at least I didn't; so it might be enough just to cut&paste the same DFWP code back.

Technorati Tags:

3 comments:

  1. Hi Jussi
    Your post has been invaluable for me making custom forms portable. Many thanks.
    I do have one question though - do you have any advice for doing something similar with the XsltListViewWebPart component? If I try to do anything with the listname or listID it won't even save in SPD.
    Thanks in advance!
    Adrian

    ReplyDelete
  2. Hi Thanks for a great post. I've deleted listname but SPD keeps adding automatically when I export the webpart. Its in the line below: Any help appreciated

    ReplyDelete
    Replies
    1. SPD will keep adding stuff all the time, that's all I can say. But the code you're referring to didn't come through to the comment...

      Delete