Set the color for a specific cell in a DataFormWebPart

…this post was published on 2013 January 1.

Starting from this topic, I will use SharePoint Designer and I will create a default DFWP for an existing list. Not the values are important but the facts.

So the the form will looks like:

First you can observe that i have 4 columns in my form and some rows. These 4 columns in the code are these line:

there are 4 tags <td> One for each column.
What i want is to color the second column’s background:Product_Type Column, in red for the second item in the list .

For this, the important env param used is position() which mean which item in the list is presented ( for each value from $Rows ) and a condition to be equal to 2.  ( this mean that is the 2. element/item in the webpart )
Also i will use Xsl:attribute to set style for that cell. The code is this one:
 <xsl:if test=”position() = 2″>
     <xsl:attribute name=”style”>background-color:red;</xsl:attribute>

and the entire code for columns is:

Second <td> – with green, mean that only  for column nr 2 i want to apply the style.
Now, my webpart looks like this:

For more infos regarding Style and Xsl coding, check this site

This entry was posted in Sharepoint Designer, XSL. Bookmark the permalink.