1,804 articles and 15,136 comments as of Sunday, May 15th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Tuesday, May 18, 2010

SharePoint: Extending the DVWP – Part 2: Layout Enhancement – Rearranging Columns – Insert Template

Author: Jim Bob Howard

In my last article, I showed you how to move the edit/delete links in the DVWP from the left side of the page, to the right.

Rinse, Repeat…
Of course, if we added the insert link, we need to do the same thing with the Insert Template.

  1. Switch Views
    Switch to the Insert Template, by clicking on the arrow (or chevron) that appears when you hover over the webpart in the Design pane.

  2. Choose the Insert Template to preview

    Sure enough, it’s out of line like the Edit Template was:


    Links on the left again!

  3. Find the template
    This time, we’re looking for the template named dvt_1.rowinsert. Click on a field (not the actual save/cancel links) in the Display pane to go directly to the template in the Code pane:
  4. <xsl:template name="dvt_1.rowinsert">
        <xsl:param name="IsInsertMode" />
        <xsl:variable name="Pos">_new</xsl:variable>
        <tr>
            <xsl:choose>
                <xsl:when test="$IsInsertMode = '1'">
                    <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
                        <td class="ms-vb" width="1%" nowrap="nowrap">
                            <xsl:call-template name="dvt_1.automode">
                                …
                          </xsl:call-template>
                        </td>
                    </xsl:if>
                    <td class="ms-vb">
                        <SharePoint:formfield … FieldName="Title" … />
                        <SharePoint:fielddescription … />
                    </td>
                    <td class="ms-vb">
                        <xsl:value-of select="@ContentType" />
                    </td>
                    . . .
                    <td class="ms-vb">
                        <SharePoint:formfield … FieldName="Expires" … />
                        <SharePoint:fielddescription … />
                    </td>
                </xsl:when>
                <xsl:otherwise>
                    <td class="ms-vb" colspan="99">
                        <a href="javascript: {…code…}">insert</a>
                    </td>
                </xsl:otherwise>
            </xsl:choose>
        </tr>
    </xsl:template>
    
  5. Edit the Template
    Again, we’ll move the template call to the bottom of the list, which will put it rightmost on our table:
  6. <xsl:template name="dvt_1.rowinsert">
        <xsl:param name="IsInsertMode" />
        <xsl:variable name="Pos">_new</xsl:variable>
        <tr>
            <xsl:choose>
                <xsl:when test="$IsInsertMode = '1'">
                    <td class="ms-vb">
                        <SharePoint:formfield … FieldName="Title" … />
                        <SharePoint:fielddescription … />
                    </td>
                    <td class="ms-vb">
                        <xsl:value-of select="@ContentType" />
                    </td>
                    . . .
                    <td class="ms-vb">
                        <SharePoint:formfield … FieldName="Expires" … />
                        <SharePoint:fielddescription … />
                    </td>
                    <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
                        <td class="ms-vb" width="1%" nowrap="nowrap">
                            <xsl:call-template name="dvt_1.automode">
                                …
                          </xsl:call-template>
                        </td>
                    </xsl:if>
                </xsl:when>
                <xsl:otherwise>
                    <td class="ms-vb" colspan="99">
                        <a href="javascript: {…code…}">insert</a>
                    </td>
                </xsl:otherwise>
            </xsl:choose>
        </tr>
    </xsl:template>
    
  7. Check the Display
    Since we edited the code, when we click on the Display pane, it goes back to the Default template. When we switch back to the Insert Template, it now looks like this:

  8. Save and Cancel are now on the right

And there you have it: Action links on the right-hand side of a DVWP for insert.

The final page layout for the Insert Template now looks like this:

Insert Template:

…which, for those of you keeping score, looks very similar to the Default and Edit Templates we edited last time.

Default Template:


Edit Template:

For more information on XSLT Templates, see Marc Anderson’s excellent series, Unlocking the Mysteries of Data View Web Part XSL Tags.

And keep an eye out for the next installment of Extending the DVWP, where we’ll talk about Turning DVWP Action Links into Buttons.

Author: Jim Bob Howard

Jim Bob Howard is a web designer / webmaster in the healthcare industry. He has been working with SharePoint since March 2009 and enjoys sharing what he has learned. He is a moderator and frequent contributor to Stump the Panel, and answers SharePoint questions on Twitter (@jbhoward) and via email ([email protected]).

View all entries in this series: Extending the DVWP»
Entries in this series:
  1. SharePoint: Extending the DVWP - Part 1: Layout Enhancement - Rearranging Columns - Default and Edit Templates
  2. SharePoint: Extending the DVWP - Part 2: Layout Enhancement - Rearranging Columns - Insert Template
  3. SharePoint: Extending the DVWP – Part 3: Getting it All on One Line - DVWP Function Action Links
  4. SharePoint: Extending the DVWP – Part 4: Turning DVWP Action Links into Buttons
  5. SharePoint: Extending the DVWP – Part 5: Doing Stuff Before Save on Submit - PreSaveAction()
  6. SharePoint: Extending the DVWP – Part 6: Examining the Form Action Links
  7. SharePoint: Extending the DVWP – Part 7: Creating a Form Action Workflow
  8. SharePoint: Extending the DVWP – Part 8: Creating a Form Action Workflow - The After Math
  9. SharePoint: Extending the DVWP – Part 9: Oops! Failed Setting Processor Stylesheet
  10. SharePoint: Extending the DVWP – Part 10: Passing Workflow Variables to a Form Action Workflow
  11. SharePoint: Extending the DVWP – Part 11: Getting More Form Fields to the Workflow
  12. SharePoint: Extending the DVWP – Part 12: Adding More Form Fields from the Data
  13. SharePoint: Extending the DVWP – Part 13: Putting PreSaveAction() to Work – Creating Variables
  14. SharePoint: Extending the DVWP – Part 14: Putting PreSaveAction() to Work with jQuery
  15. SharePoint: Extending the DVWP – Part 15: User-Managed Dropdowns with Site Columns
  16. SharePoint: Extending the DVWP – Part 16: User-Managed Dropdowns - Loading Data
  17. SharePoint: Extending the DVWP – Part 17: User-Managed Dropdowns – Creating a Relationship list
  18. SharePoint: Extending the DVWP – Part 18: User-Managed Dropdowns – Loading the Relationship list – Part 1
  19. SharePoint: Extending the DVWP – Part 19: User-Managed Dropdowns – Loading the Relationship list – Part 2
  20. SharePoint: Extending the DVWP – Part 20: Cascading Dropdowns - Applying the jQuery
  21. SharePoint: Extending the DVWP – Part 21: Cascading Dropdowns - Three-tier Cascade
  22. SharePoint: Extending the DVWP – Part 22: Creating Title Based on Other Fields with jQuery
  23. SharePoint: Extending the DVWP – Part 23: Creating Title Based on Other Fields with a Workflow
  24. SharePoint: Extending the DVWP – Part 24: A Note to Readers
  25. SharePoint: Extending the DVWP – Part 25: Using an Audit Trail by Creating List Items with SPServices
  26. SharePoint: Extending the DVWP – Part 26: Modifying the Edit Template
  27. SharePoint: Extending the DVWP – Part 27: Adding an Alternate Edit Template to a DVWP
  28. ExSharePoint: Extending the DVWP – Part 28: Massage the Remove Template
  29. SharePoint: Extending the DVWP – Part 29: Modifying Form Action Workflows on the remove Template
  30. SharePoint: Extending the DVWP – Part 30: Using EasyTabs with Filtered DVWPs to Make Data Manageable
  31. SharePoint: Extending the DVWP – Part 31: Filling in Default Data on the insert Template with jQuery
  32. SharePoint: Extending the DVWP – Part 32: Filling in Default Data on the insert Template with Multiple DVWPs
  33. SharePoint: Extending the DVWP – Part 33: Modifying Total and Subtotal Row Layouts in DVWP
  34. SharePoint: Extending the DVWP – Part 34: Using Icons for Form Action Links
  35. SharePoint: Extending the DVWP – Part 35: Putting it All Together
  36. SharePoint: Extending the DVWP – Bonus: Fixing the Insert Form Action When "No Matching Items"
  37. SharePoint: Extending the DVWP – Bonus: Creating a Title Based on Dropdowns with jQuery
 

Please Join the Discussion

5 Responses to “SharePoint: Extending the DVWP – Part 2: Layout Enhancement – Rearranging Columns – Insert Template”
  1. Richard says:

    Hello Jim,

    Thank you sir for these excellent articles! I am happy that you took the time to write them. I wanted to know if you have had any trouble getting the insert link to work on the no matching items template. I inserted it on that template, but for some reason, it won’t render the insert template from there. I was told it is possible, but I can’t seem to get it to work. It posts back without any errors, but renders the wrong template. It just won’t do it without a record in the recordset. I am using SPD 2010 and a DVWP, and the page is filtered with a query string parameter. What steps am I missing? Thanks again.

    • Thanks, Richard. And you’re welcome.

      Yes, I’ve run into that same issue with the DVWP. Definitely a bug that wipes out the appropriate template call when the list is empty. YMMV, but I’ve seen it only after I’ve edit the “empty” message. When it’s the default message, everything seems to work fine. But once I edit it, the link no longer appears.

      In the SPD Design pane, the work around is to check the “Show sample data” box, which tells SPD to simulate having data. This allows you to work with the link, at least. In the actual rendered page, it’s a bit more complicated once it’s been wiped out. Sounds like an addendum to the series that I need to write. ;)

      I’ll do that.

      Blessings,
      Jim Bob

Trackbacks

Check out what others are saying about this post...
  1. [...] that first two articles in this series, Extending the DVWP: Layout Enhancement – Rearranging Columns…, we moved the action links from their default left-most column [...]

  2. [...] The first thing is to Rearrange the Columns to get the edit and delete links on the right side of the page. We’ll have to do that for the default template, the edit template, and the insert template. [...]

  3. [...] Richard asked a great question: "Have you had any trouble getting the insert link to work on the no matching items template?" [...]




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!