Click here to Skip to main content
12,350,035 members (26,174 online)
Rate this:
 
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 8:34am
Edited 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))
VijayChauhan123 4-Oct-12 1:26am
   
yes Trilok Arora is correct, you change the forecolor instead of backcolor

1 solution

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

Solution 1

  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2016
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