Home > DeveloperSection > Forums > change forecolor af a special word in gridview cell
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    January-22-2014 11:57 PM

 C# C# 
Ratings:


 1 Reply(s)
 706  View(s)
Rate this:

I want to change a color of a special word NOT all words of a gridview Cell . here is event 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 might be like here :"Radioactive : Danger" or this : "Human Body : Special ,Perishable " what should I do?



Pravesh Singh

Total Post:411

Points:2881
Posted on    January-23-2014 1:01 AM

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;

        }

    }


Don't want to miss updates? Please click the below button!

Follow MindStick