HTML calculated column and Data View Web Part

This is a technical post that assumes you are familiar with the HTML calculated column and the Data View Web Part.

I recently published a new version of my “HTML calculated column” script. It works fine in list views and calendar views, but not with the Data View Web Part. Let’s take a closer look.

As an example, I’ll use a calculated column called “Indicator” with the following formula:

="<IMG src='/_layouts/images/kpiryg-"&(3-RIGHT(LEFT(Priority,2),1))&".gif' />"

If for example the priority is low, the following result will be displayed in list view:
<IMG src=’/_layouts/images/kpiryg-0.gif’ />

Applying the “HTML calculated column” method on top of this will render the kpiryg-0.gif image.

If however you use a DVWP, here is what you’ll see:
&lt;IMG src=&#39;/_layouts/images/kpiryg-0.gif&#39; /&gt;

Special characters are escaped: &lt; for “<“, &gt; for “>”, &#39; for single quotes.

Let’s take a closer look at the source code behind the DVWP. The code that renders the Indicator field depends on how you created the DVWP:
1/ Directly from the data source library, using the “Insert Selected Fields” option:

<td class="ms-vb">
	<xsl:value-of select="@Indicator"/></td>

2/ By converting a list view:

			<TD Class="{$IDAXOQVC}"><xsl:value-of disable-output-escaping="yes" select="ddwrt:AutoNewLine(string(@Indicator))" /></TD>

Change the code as follows:

<td class="ms-vb">
<xsl:value-of disable-output-escaping="yes" select="@Indicator" />

With the modified code, the field will display the same way as in a list view:
<IMG src=’/_layouts/images/kpiryg-0.gif’ />

You can now apply the usual script, and have your string rendered as HTML.


13 thoughts on “HTML calculated column and Data View Web Part

  1. Pingback: HTML calculated column and Data View Web Part « Path to SharePoint | Webmaster Tools

  2. Pingback: HTML calculated column and Data View Web Part « Path to SharePoint

  3. Hi,

    I also posted on endusersharepoint about this. Thanks for any help.

    I can create a button in a calculated column using Cristophe’s HTML converter web part.

    But I would l;ike it to perform the same function as a form button we have in the quick launch menu. The Calc column button should capture the field from one id which would be roadID, we don’t need the other milestart param. I can’t seem to be able to attach the function to the button.

    Here is the code for the asp button we want to make work in a calc column. Thank you very much.

  4. @ Christophe,
    Thanks for the updated script!
    How would you perform calculations ‘cross-list’?

    • Chris, in all your work with calculated columns and the CEWP, DVWP – do you know if Silverlight can be used to do the same things? Maybe its so new that none of the developers have gotten hold of it yet, but I read a blog the other day where this guy showed how it could be used to display a SQL database, and such. I read where Silverlight is a new competitor to FLASH and products like that, but has other capabilites and can be used with SharePoint. Whats your take?


  5. Tom: I am not familiar with SilverLight development, but I would expect it to allow you to do most of the stuff I am doing here. Same for Flash.
    My take: the trend I am seeing is an increased use of JavaScript libraries (like jQuery) that are taking over animations that were traditionally done with Flash. Why use proprietary software when you can achieve the same result with standard tools?

  6. Just want to ask if there is a way on how to render a button in a calculated column?

    Thanks in Advance.

  7. I use this to have a button in the column to pass a parameter to an html form which opens an in-house aplication we run.


  8. Pingback: HTML Calculated Column: solutions for SP 2010 (Part II) « Path to SharePoint

  9. Hi, I am a bit of a noob at Sharepoint, but am doing some stuff with dashboards in SP 2007 and came across your DVWP and projects templates. I really like these, and am trying to use them, and so far so good except for adjusting the columns in the DVWP. I am working only with the XSL editor, and do not have SP Designer, and have got as far as being able to add a new column (in the list and the DVWP), but although the calculation is in the field in the list for the image to show, it is not showing on the DVWP. Is there somewhere else that I have to add my new field (column) to get it to show?


Comments are closed.