title: How to cycle with dates?
body: <p>I would need to color the days of a months using a datepicker with the following logic: starting from a date in database, i would like to color in orange next 8 days, then next 2 days in green and so on for every following month.</p>
  
  <p>I have the following code but i need a loop:</p>
  
  <pre><code>private void calFecha_DayRender(object source, DayRenderEventArgs e)  
  {
      if (ddloperadores.SelectedValue != "Todos")
      {                
          DataTable asistencia = OperadoresForaneosAsistencia((int)WAPS.Globals.ConvertTo(txtNumOperador.Text, 0)).Tables[0];                  
  
          if (asistencia.Rows.Count &gt; 0)
          {
              DataRow iRow = asistencia.Rows[0];
              string Tipo = iRow["TipoJornada"].ToString();
              Tipo = asistencia.Rows[0]["TipoJornada"].ToString();
  
              if (Tipo == "1") //Tipos de Jornadas
              {
                  DateTime FechaJornada = Convert.ToDateTime(iRow["Jornada_Ini"]);                      
                  DateTime fechatemp = DateTime.Today;                        
                  DateTime primero = new DateTime(fechatemp.Year, fechatemp.Month, 1);
                  DateTime ultimo = new DateTime(fechatemp.Year, fechatemp.Month + 1, 1).AddDays(-1);                      
  
                  int counter = 1;
                  for (DateTime n = FechaJornada; n &lt;= ultimo; n=n.AddDays(1))
                  {
                      int rem = counter % 10;
  
                      if (rem &gt;= 1 &amp;&amp; rem &lt;= 8)
                      {
                          e.Cell.BackColor = System.Drawing.Color.DarkGreen;
                      }
                      else
                      {
                          e.Cell.BackColor = System.Drawing.Color.DarkOrange;
                      }
  
                      counter++;
                  }                        
              }
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/872jh.png" rel="nofollow noreferrer">calendar image</a></p>