---
title: "change forecolor af a special word in gridview cell"  
description: "change forecolor af a special word in gridview cell"  
author: "Anonymous User"  
published: 2014-01-22  
updated: 2014-01-23  
canonical: https://www.mindstick.com/forum/1863/change-forecolor-af-a-special-word-in-gridview-cell  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# change forecolor af a special word in gridview cell

I want to change a [color](https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp) of a special [word](https://www.mindstick.com/forum/305/read-word-file) NOT all words of a [gridview](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) Cell . here is [event](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london) and codes:

```
protected void gvContents_RowDataBound(object sender, GridViewRowEventArgs e){    if (e.Row.RowType == DataControlRowType.DataRow)    {        if (e.Row.Cells[3].Text.Contains("Special"))        {            //set The "Special" word only forecolor to red        }        else if (e.Row.Cells[3].Text == "Perishable")        {            //set The "Perishable" word only forecolor to blue        }        else if (e.Row.Cells[3].Text == "Danger")        {            //set The "Danger" word only forecolor to yellow        }    }}
```

and Cell [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) might be like here :"Radioactive : Danger" or this : "[Human Body](https://yourviews.mindstick.com/story/1503/6-of-the-weirdest-and-wackiest-facts-on-the-human-body) : Special ,Perishable " what should I do?

## Replies

### Reply by Pravesh Singh

Hi ankita,\

In the CellFormatting event handler, add the below code

```
void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)    {        if (e.Value != null && e.Value.ToString() == "Special")        {            e.CellStyle.ForeColor = Color.Red;        }    }
```


---

Original Source: https://www.mindstick.com/forum/1863/change-forecolor-af-a-special-word-in-gridview-cell

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
