Click here to Skip to main content
14,870,735 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to change the grid view cell text color based on my logic. Can you help me out to solve this problem.
Thanks in advance
Updated 12-Mar-15 2:46am
King Fisher 12-Mar-15 8:47am
What have you tried?
Nitij 13-Mar-15 8:31am
You can do this by so many ways, like from Row Created event, from JavaScript etc. Have you even tried to find a solution?

This is very simple task. We can make use of the RowDataBound event handler.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.DataRow)
            if (e.Row.Cells[2].Text == "pass")
                e.Row.Cells[2].ForeColor = System.Drawing.Color.Green;
            else if (e.Row.Cells[2].Text == "Fail")
                e.Row.Cells[2].ForeColor = System.Drawing.Color.Red;

Refer: Dynamically change text color in gridview in C#
You can also manipulate your html elements in jquery/javascript using classes or ID. So push button f12 and select the element you want to manipulate to get the its ID or class, then manipulate it using jquery/javascript.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900