Click here to Skip to main content
Rate this: bad
good
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 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
if(Convert.ToBoolean(args.row.Cells[22].text))
VijayChauhan123 at 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

Please follow the link..somehow it may help you.
 

Display Colored Items in DataList at runtime and handling the DataListItem CheckBox event [^]
 

Thanks
  Permalink  

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

  Print Answers RSS
0 Nirav Prabtani 268
1 OriginalGriff 217
2 Mika Wendelius 185
3 CPallini 170
4 _Amy 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 CPallini 170


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