---
title: "Row coloring of GridView Control according to its column  value?"  
description: "Row coloring of GridView Control according to its column  value?"  
author: "Pravesh Singh"  
published: 2012-09-10  
updated: 2012-09-11  
canonical: https://www.mindstick.com/forum/447/row-coloring-of-gridview-control-according-to-its-column-value  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Row coloring of GridView Control according to its column  value?

Hello Guys,

I’m facing a [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) since last night; actually I’ve a SQL table which containing some information such as ID, Name, Address, [Email](https://www.mindstick.com/articles/12870/10-easy-ways-to-manage-your-business-email-inbox), [Password](https://www.mindstick.com/blog/118/retriving-user-password-by-using-stored-procedure-in-asp-dot-net), Age, Contact No. etc and this table [structure](https://www.mindstick.com/articles/23258/choose-your-business-structure-wisely) is [binding](https://www.mindstick.com/blog/146/dynamic-binding-in-c-sharp) with [GridView](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control). I want to display record in GridView control with coloring row; suppose that If age is greater than 18 then row [background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp) of that data is yellow and if age is under 18 then row background of that row is orange something like that.

Please let me know how it will [resolve](https://www.mindstick.com/forum/159427/windows-app-dll-not-found-resolve-library-issue) I don’t have an idea about it. If possible, please paste [your code](https://www.mindstick.com/forum/157976/how-can-you-use-jquery-s-testing-framework-such-as-qunit-to-write-unit-tests-for-your-code) here.

Thanks !!

## Replies

### Reply by Anonymous User

Hey Pravesh,\
It is quite easy to implement, to resolve this problem you have to use GridView1_RowDataBound event and write down the following line code:\

```
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    {                if (e.Row.RowType == DataControlRowType.DataRow)           {            string val = DataBinder.Eval(e.Row.DataItem, "age").ToString(); // get the value of age column                     if (val<= 18) // check whether age is less than 18          {              e.Row.BackColor = Color.Orange;           }          else if (val>= 18) // check whether age is greater than 18          {              e.Row.BackColor = Color.Yellow;           }          else // if above two conditioned are not true          {              e.Row.BackColor = Color.Gray;                       }        }}
```

\
I hope this line of code might be resolve your problems. Please marked as answer if this code will help you.\
\
Regards,\
Arun Singh


---

Original Source: https://www.mindstick.com/forum/447/row-coloring-of-gridview-control-according-to-its-column-value

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
