Showing posts from August, 2012

Test for Null in XSLT Data View

If you insert a data view webpart and then style the td cells for borders, it will not style the empty cells.  Very annoying.  One way to fix this is to use the xsl:choose tag to do an if/otherwise test for null.<xsl:choose><xsl:when test="categoryName !=null">        <xsl:value-of select="categoryName " /></xsl:when><xsl:otherwise>        <xsl:value-of select="other" /></xsl:otherwise></xsl:choose>

vertical-align - Why it sucks and how it is used

Okay so sometimes vertical-align just doesn't do what you expect, in fact it seems it rarely does.

Here is how to use it:

<td valign="middle"> <!-- but you shouldn't ever use valign --> </td> <td style="vertical-align:middle"> ... </td> <div style="display:table-cell; vertical-align:middle"> ... </div>

Or this works well:

DIV.container {
    min-height: 10em;
    display: table-cell;
    vertical-align: middle }

Here is a link to the full explanation for it's intentions:

SharePoint–Data View Webpart Show Total Items in a list

There are times when I want to show a distinct dashboard style rollup of items in a list which match certain conditions.  There isn’t a lot of documentation online on XPath expressions for SharePoint Data View webparts.  Here is sample code to calculate the count of rows in a list.  Be careful to choose the right column to count so that you are guaranteed to get the total you expect.

I have included styling as an example because, why wouldn’t we style the results?

<style type=”text/css”>
.DVRow {
font:normal normal bold 20px Calibri;
<td class=”DVRow”>

<asp:Label runat=”server” id=”ff1{$Pos}” text=”{count(/dsQueryResponse/Rows/Row/@Title)}” __designer:bind=”{ddwrt:DataBind('u', concat('ff1',$Pos), 'Text','','ID',ddwrt:EscapeDelims(string(@ID)),'count(/dsQueryResponse/Rows/Row/@Title')}” />

Pay close attention to the XPath formula: count(<a>/dsQueryResponse/Rows/Row/@Ti…

SharePoint - Data View Webpart - Return your customer back to your Data View

After your customer links to and then submits the form, they are redirected to the default list view of the SharePoint list. For most scenarios, it makes more sense to have the customer return to the Data View from which they came. In order for this to happen, the URL that you jump to must include the Source=URL name/value pair. You can make the system add this name/value pair for you automatically by adding two attributes to your link.Create or open a Data View, and then switch to Split or Code view. Go to the <xsl:template name="dvt_1.rowview"> sub-node of the <WebPartPages:DataFormWebPart> tag. Locate the <a> tag that formats the field value. For example:
<td class="ms-vb">
<a href="http://northwindtraders/Lists/Products/EditForm.aspx?ID={@ID}">
<xsl:value-of select="@Product_x0020_Name"/>

Add the attributes to the <a> tag that enable the link to return the customer to thi…

SharePoint - Add New! icon to Data View Webpart

To show the standard SharePoint icon against new list items in a data view web part (or other XSLT web parts), use the following snippet:

<xsl:if test="ddwrt:IfNew(string(@Created))">
<img src="/_layouts/1033/images/new.gif" alt="New"/>

Edit the Data View Webpart Footer

Often I use a Data View webpart just so I can style everything in it. It may be hard to understand how the footer of the webpart is styled, but once you see the elements by themselves it isn’t too bad.
Here is the Footer Section with my CSS (background color of entire webpart is #212121):

< style type="text/css">
.Footer {
background-color:#212121; text-align:right; color:#CCCCCC; font-family:”Segoe UI”; font-size:11px; border-top:1px solid #111111; }
.FooterText {
font-family:”Segoe UI”; font-size:12px; color:#EEEEEE; }
.FooterText a:link, .FooterText a:visited {
text-decoration:none; cursor:hand; color:#EEEEEE; }
.FooterText a:hover {
text-decoration:underline; cursor:hand; color:#EEEEEE; }

<td nowrap=”" class=”Footer“>
<xsl:if test=”$dvt_firstrow &gt; 1″ ddwrt:cf_ignore=”1″> <a> <xsl:attribute name=”href”> javascript: <xsl:value-of select=”ddwrt:GenFireServerEvent(‘dvt_firstrow={1};dvt_startposition={}’)” />; </xsl:attribute> <span cl…