---
title: "Change color of row based on value of a column in the row"  
description: "Change color of row based on value of a column in the row"  
author: "Anonymous User"  
published: 2014-08-23  
updated: 2014-08-23  
canonical: https://www.mindstick.com/forum/2103/change-color-of-row-based-on-value-of-a-column-in-the-row  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# Change color of row based on value of a column in the row

I have an sqldatasource that loads, [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) from my [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) and puts it in a datagrid.

What I want is that each [row](https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table) have a different [color](https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp) depending on which number is in that datarow [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server)

```
$(document).ready(function () {    $("#<%=GridView1.UniqueID%> tr").each(function () {        var number = $(this).children('td:eq(6)').text();        if (number == 'OK') {            $(this).children('td').css({ "background-color": "lightgreen" });        }    })});
```

## Replies

### Reply by Sumit Kesarwani

Hi John,

Granted you've given your gridview a css class called 'myGridView' you could do the following:

```
$(document).ready(function () {    $('.myGridView
tr').each(function () {        var number =$(this).children('td:eq(1)').text();        if (number =='1') {           
$(this).children('td').css('background', 'red');        }    })});
```

where 'td:eq(1)' refers to the second cell in a row. This of course will depend on what cell in your row contains this magic number.

I'm certain it's not the most elegant use of jQuery, but you could refactor it as you wish.


---

Original Source: https://www.mindstick.com/forum/2103/change-color-of-row-based-on-value-of-a-column-in-the-row

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
