Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi, I have a colum in datagrid called "Colum22",
I want to change the color of the data when "True" occurs

C# code :

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 3-Oct-12 9:34am
Edited 3-Oct-12 9:38am
Sandeep Mewara at 3-Oct-12 16:04pm
What do you see when you debug?
Trilok Arora at 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 at 4-Oct-12 0:46am
Good Catch
itskvini at 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
VijayChauhan123 at 4-Oct-12 1:26am
yes Trilok Arora is correct, you change the forecolor instead of backcolor

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 229
1 OriginalGriff 225
2 Suvendu Shekhar Giri 205
3 PIEBALDconsult 180
4 Peter Leow 135
0 Sergey Alexandrovich Kryukov 6,434
1 OriginalGriff 6,033
2 Peter Leow 2,534
3 Maciej Los 2,268
4 Abhinav S 2,264

Advertise | Privacy | Mobile
Web01 | 2.8.150414.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100