Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a colum in datagrid called "Colum22",
I want to change the color of the data when "True" occurs

C# code :

C#
Protected voide ongridrowdatabound(object sender, GridRowevent args)
{
args.row.Cells[22].ForeColor =System.Drawing.Color.Red;
if(args.row.Cells[22].text == "True")
{
for (int i=1;i<args.Row.Cells.Count;i++)
{
args.Row.Cells[i].Backcolor = System.Drawing.Color.DarkGray;
}
}
ERROR: This code changes the column data irrespective of the IF condition (All the columns are turned in to RED color ) Please give me a solution
Thanks in advance ....
Posted
Updated 3-Oct-12 8:38am
v2
Comments
Sandeep Mewara 3-Oct-12 16:04pm    
What do you see when you debug?
Trilok Arora 3-Oct-12 17:26pm    
In your code, you set the ForeColor to Red and never change the forecolor to any other color, but you are changing the backcolor based on IF condition. Thats why your forecolor is always Red
itskvini 4-Oct-12 0:46am    
Good Catch
itskvini 4-Oct-12 0:50am    
Also don't use condition like
if(args.row.Cells[22].text == "True")
Convert it to boolean if the values are "True" or "False", use
if(Convert.ToBoolean(args.row.Cells[22].text))
Rockstar_ 4-Oct-12 1:26am    
yes Trilok Arora is correct, you change the forecolor instead of backcolor

1 solution

 
Share this answer
 

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