Click here to Skip to main content
14,845,771 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
Posted
Updated 12-Mar-15 2:46am
v2
Comments
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.
  1  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  2      {
  3          if (e.Row.RowType == DataControlRowType.DataRow)
  4          {
  5              if (e.Row.Cells[2].Text == "pass")
  6              {
  7                  e.Row.Cells[2].ForeColor = System.Drawing.Color.Green;
  8              }
  9              else if (e.Row.Cells[2].Text == "Fail")
 10              {
 11                  e.Row.Cells[2].ForeColor = System.Drawing.Color.Red;
 12              }
 13          }
 14      }


Refer: Dynamically change text color in gridview in asp.net 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