Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int esal = int.Parse(e.Row.Cells[3].Text.ToString());
            if (esal > 12000)
            {
                e.Row.ForeColor = System.Drawing.Color.Blue;
                e.Row.BackColor = System.Drawing.Color.LightPink;
                e.Row.Font.Italic = true;
            }
            else if (esal == 15000)
            {
                e.Row.ForeColor = System.Drawing.Color.Brown;
                e.Row.BackColor = System.Drawing.Color.LightBlue;
                e.Row.Font.Italic = true;
            }
            else
            {
                e.Row.ForeColor = System.Drawing.Color.White;
                e.Row.BackColor = System.Drawing.Color.LightGreen;
                e.Row.Font.Italic = true;
            }

        }




I tried this ,but i got an exception in this ...input string was not a correct format ...please help me
Posted
Updated 25-Sep-13 2:58am
v3

C#
foreach (GridViewRow row in yourGridView.Rows) {
      row.BackColor = Color.Green;
 }
 
Share this answer
 
Comments
Siva Hyderabad 25-Sep-13 8:44am    
fine,but its based on column salary based...colors will be changed...that y am i using this
You error has nothing to do with colors and all that stuff. Error must be at first line of your code.That is:
int esal = int.Parse(e.Row.Cells[3].Text.ToString());

Replace this with below code:
C#
int esal= string.IsNullOrEmpty(e.Row.Cells[3].Text) ? 0 : int.Parse(e.Row.Cells[3].Text);

Regards...
 
Share this answer
 
Comments
Siva Hyderabad 26-Sep-13 0:13am    
Replace with your code.. but it shows like same above...
Thanks7872 26-Sep-13 0:18am    
Then check the value which you tried to convert to int. The reason i provided this is,in your code,if you have empty text that is e.Row.Cells[3].Text as empty string than it will throw an error.If you use mine,then it will take 0 whenever there is empty string. If you still get an exception,its clear that the value in e.Row.Cells[3].Text is not valid to be converted to int.

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