Click here to Skip to main content
15,894,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,
In a gridview i am trying to give color to a cell depending on its value from database.below i the code. but it give green color to all. which is else part.whats wrong.
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{    
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((string.IsNullOrEmpty(e.Row.Cells[3].Text) != true) 
                  || (e.Row.Cells[3].Text != " "))
            {
                string result = (e.Row.Cells[3].Text);
                if (result == "not working")
                    e.Row.Cells[3].BackColor= System.Drawing.Color.DarkRed;
                else
                    e.Row.Cells[3].BackColor= System.Drawing.Color.DarkOliveGreen;
             }
         }    
}
Posted
Updated 22-Jul-13 23:00pm
v4
Comments
Thanks7872 23-Jul-13 4:43am    
I think you are not clear at your condition and you just lost in that. What are the conditions based on which you want to change the color of the cell?
Prasaad SJ 23-Jul-13 4:49am    
Did you Debug and check, What is the value for the result each time? I think there might be some problem in extracting the data("Text"). Can you specify the result value here?

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