I would like to change the background color on my gridview based on current date. The code below works, but the future date which will be colored in blue starts two days later instead of 1 day which is tomorrow. Am I missing something in the code or should it be modified differently? .
If e.Row.RowType = DataControlRowType.DataRow Then Dim data As DateTime = Convert.ToDateTime(DirectCast(e.Row.DataItem, DataRowView)("Date").ToString()) Dim diff As TimeSpan diff = DateTime.Now.Subtract(data) Dim days As Integer = diff.Days 'Yellow = past date / White = current date / Blue = future date If days > 0 Then e.Row.BackColor = Drawing.ColorTranslator.FromHtml("#FFFFBB") 'past date' ElseIf days < 0 Then e.Row.BackColor = Drawing.ColorTranslator.FromHtml("#BAD8FF") 'future date' ElseIf days = 0 Then 'present date 'do nothing End If End If