Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Frnds ,

On my Webform I have a Gridview, and below is my code for column color change.

C#
if (getDate2 < dt3)
            {
                item.Cells[4].BackColor = Color.Green;
            }
            else
            {
                item.Cells[4].BackColor = Color.Red;
            }

            if (getDate2 > dt4)
            {
                item.Cells[5].BackColor = Color.Red;
            }
            else
            {
                item.Cells[5].BackColor = Color.Green;
            }


Please can u Suggest me how to give color code for this. I need a light color for green and RED.

for Example # 00FF00 (Light Green)
# #FF6666 (Light RED)

i need this above colors in that code. please help me.


THANKS,
Posted

Hi,
You can try this
C#
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.DataRow )
       {
           if (e.Row.Cells[1].Text == "1")
           {
               e.Row.Cells[1].BackColor = Color.Red;
           }
       }
   }

Best Regards
M.Mitwalli
 
Share this answer
 
v2
Comments
Syed SufiyanUddin 16-Apr-12 4:00am    
where should i write this code
Mohamed Mitwalli 16-Apr-12 4:23am    
Write it in RowDataBound hope it will work for you
hi,you can use this code
C#
GridView1.Rows[1].Cells[1].BackColor = System.Drawing.Color.Red;

and in below link is list of colors :

Colors in ASP.NET
 
Share this answer
 
v4
Comments
Syed SufiyanUddin 16-Apr-12 4:48am    
Thank u so Much Dear.
Hi,

using Following code u can convert color code to color

C#
Color clr = ColorTranslator.FromHtml("#FFFF33");


hope this help u
best Luck
happy Coding :)
 
Share this answer
 
v2

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