Skip to main content Skip to footer

Formatting Column Cells based on Data Value

This example highlights the cell value in the DateTime column based on the day of week.

ASP.NET Web Forms GridView Conditional Formatting

protected void C1GridView1_RowDataBound(object sender, C1.Web.Wijmo.Controls.C1GridView.C1GridViewRowEventArgs e)  
        {  
            if (e.Row.RowType == C1GridViewRowType.DataRow)  
            {  
                        DateTime dt = new DateTime(long.Parse(e.Row.Cells[1].Text) * 10000).AddYears(1969);  
                        if (dt.ToString("dddd") == "Monday")  
                        {  
                            e.Row.Cells[1].BackColor = System.Drawing.Color.Red;  
                        }  
                        if (dt.ToString("dddd") == "Tuesday")  
                        {  
                            e.Row.Cells[1].BackColor = System.Drawing.Color.Green;  
                        }  
                        if (dt.ToString("dddd") == "Wednesday")  
                        {  
                            e.Row.Cells[1].BackColor = System.Drawing.Color.Yellow;  
                        }  
                        if (dt.ToString("dddd") == "Thursday")  
                        {  
                            e.Row.Cells[1].BackColor = System.Drawing.Color.Blue;  
                        }  
                        if (dt.ToString("dddd") == "Friday")  
                        {  
                            e.Row.Cells[1].BackColor = System.Drawing.Color.Orange;  
                        }  
                        if (dt.ToString("dddd") == "Saturday")  
                        {  
                            e.Row.Cells[1].BackColor = System.Drawing.Color.Violet;  
                        }  
                        if (dt.ToString("dddd") == "Sunday")  
                        {  
                            e.Row.Cells[1].BackColor = System.Drawing.Color.Indigo;  
                        }  
                        }  
        }  

One important thing in the above code is that the Wijmo Gridview date column returns JSON string for cell's Text when 'e.Row.Cells[1].Text' is used .To parse this string in to Date object the formula used is : DateTime dt = new DateTime(long.Parse(e.Row.Cells[1].Text) * 10000).AddYears(1969);