Sharepoint: Apply background color to custom list column based on other column value

Today we are going to learn how to apply the background color to a custom list column based on other column value, firstly, I tried this scenario using calculated formula column type but some javascript code is needed to render the background color based on calculated formula value,  so I did some research and come up with the best easy way…..

STEPS:

I have created a simple custom list and name it as ‘My List

Modified the ‘Title‘ column name as ‘Student Name

Created one more column ‘Subject‘ which is of type single line text

Also, created one column ‘Marks‘ which is of type Number min is 1 and max is 100

Open the AllItems.aspx page using Sharepoint Designer 2007

Select the list, right click and Convert into XSLT mode

Write the XSL condition in between the ‘SubjectTD tag as show in the below image

Here goes the XSL code……

<!–custom code for background color starts–>

<xsl:choose>
<xsl:when test=”@Marks &gt;=’70′”>
<xsl:attribute name=”style”>background-color:Green;</xsl:attribute>
</xsl:when>
<xsl:when test=”@Marks &lt;=’70’ and @Marks &gt;=’50′”>
<xsl:attribute name=”style”>background-color:Yellow;</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name=”style”>background-color:Red;</xsl:attribute>
</xsl:otherwise>
</xsl:choose>

XSL condition in Sharepoint Designer 2007
XSL condition in Sharepoint Designer 2007

Output:

Background color to Sharepoint Custom List column based on Marks
Background color to Sharepoint Custom List column based on Marks

Similar Posts

7 Comments

  1. i followed excactly the steps, but no luck
    below is the code of my list

    background-color: Green;

    background-color: Yellow;

    background-color: Red;


  2. The code disappear, can you please give me your email, so i can email the code.

    apprecitae your help. as im realy need this featuse on my list

  3. Hi – I was wiennrodg if you know how to modify the people search results so that the manager name shows up. I have not been able to do that. Thanks, Abby

Comments are closed.