views:

213

answers:

1

I have a gridview that displays data from a DB... Currently I can only change colors of all the texts in a cell, but what I need to do is to change the color of certain texts only. Is there a way to do this? Is this possible? Im just a newbie so please be patient with me..

This is my function for changing color of texts in cells:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
{  
    if (_SearchKey != string.Empty)  
    {  
        if (e.Row.RowType == DataControlRowType.DataRow)  
        {  
            for (int ctr = 0; ctr < e.Row.Cells.Count; ctr++)  
            {  
                if (e.Row.Cells[ctr].Text.ToLower().Contains(_SearchKey.ToLower()))  
                {  
                    e.Row.Cells[ctr].ForeColor = System.Drawing.Color.Red;  
                }  
            }  
        }  
    }  
}  
+1  A: 

Have a look at this tutorial

Another way is to use Template Field inside GridView Control

Asad Butt
+1. Beat me to it.
David Stratton
Sorry Sir but I still dont get it... I know that it can be formatted based on data but what I need to do is to format certain part of the whole texts in a cell of a gridview. For example the following texts is in a cell of a gridview: "Software and hardware." if the search key is "ware", the two instances of the text "ware" will become color red but the texts "Soft", "and", "Hard" will still be black... "Sofware
Kuroro
This is a different requirement now. would you mind using javascript!here is the article for that http://www.nsftools.com/misc/SearchAndHighlight.htm, and http://www.tedpavlic.com/post_simple_inpage_highlighting_example.php
Asad Butt