title: Telerik Rad Calendar - Is Changing Data Source Possible?
body: <p>I'm trying to change the dates displayed in a RadCalendar. For example, I want it to begin 2 weeks before the current date and ends two weeks after the current date. Is it possible?</p>
  
  <p>I was able to change the text displayed in the cells (to display the "new" date) but the "OnClick" methods still sends the "old" date.</p>
  
  <p>OnDayRender I added :</p>
  
  <pre><code>e.Cell.Text = "&lt;a href=\"#\"&gt;" + _calStartDate.Day.ToString() + "&lt;/a&gt;";
  _calStartDate = _calStartDate.AddDays(1);
  </code></pre>
  
  <p>But the calendar still thinks that the new dates are the old one, so the "SelectedDate" method returns the "old" date and the date selected is not the current date. </p>
  
  <p>Is there a way to just pass a new list of dates, which would be easier?</p>
  
  <p><strong>UPDATE / Solution:</strong></p>
  
  <p>I was able to make it work like that:</p>
  
  <pre><code>    private int rowCounter = 0;
  
      private int rowHeaderCnt = 0;
  
      private DateTime _startDate;
      private DateTime _endDate;
  
      private DateTime _calStartDate;
      private DateTime _calEndDate;        
  
  protected void radCalendar_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
      {
          TableRow tr = (TableRow)e.Cell.Parent;
          Table table = (Table)tr.Parent;
  
          if (e.Day.Date.CompareTo(_calStartDate) &lt; 0)
          {
              ((TableRow)(e.Cell.Parent)).Style["display"] = "none";
          }
          else if (e.Day.Date.CompareTo(_calEndDate) &gt; 0)
          {
              ((TableRow)(e.Cell.Parent)).Style["display"] = "none";
          }
          else if (e.Day.Date.DayOfWeek == DayOfWeek.Sunday)
          {
              // This part will change the week number cell (if you don't display it, hide this part)
              rowCounter++;
              TableCell cellRowHeader = ((TableRow)(e.Cell.Parent)).Cells[0];
              cellRowHeader.Text = rowCounter.ToString();
          }
  
      }
  
      protected void Page_Load(object sender, EventArgs e)
      {
          radCalendar.RangeMinDate = _startDate;
          radCalendar.RangeMaxDate = _endDate;
      }
  
     protected void radCalendar_HeaderCellRender(object sender, Telerik.Web.UI.Calendar.HeaderCellRenderEventArgs e)
      {
          if (e.HeaderType == Telerik.Web.UI.Calendar.HeaderType.Row)
          {
              rowHeaderCnt++;
              e.Cell.Text = "&amp;nbsp;" + rowHeaderCnt;
          }
  
          if (e.HeaderType == Telerik.Web.UI.Calendar.HeaderType.Column)
          {
              TableRow row = ((TableRow)(e.Cell.Parent));
              row.Cells[0].Text = "&amp;nbsp;" + StringUtil.getStringByLanguage("Week", "Sem.") + "&amp;nbsp;";
          }
  
      } 
  
  
      protected void raCalendar_SelectionChanged(object sender, Telerik.Web.UI.Calendar.SelectedDatesEventArgs e)
      {
          DateTime startDate = new DateTime();            
          DateTime endDate = new DateTime();
          String url = String.Empty;
  
          if (e.SelectedDates.Count == 1)
          {
              startDate = e.SelectedDates[0].Date;
              endDate = e.SelectedDates[0].Date;
          }
          else
          {
              startDate = e.SelectedDates[0].Date;
              endDate = e.SelectedDates[e.SelectedDates.Count - 1].Date;
          }
  
         // ... add code here with startDate and endDate
  
      }
  
      public void initCalendar(DateTime startDate, DateTime endDate)
      {
          this._startDate = startDate;
          this._endDate = endDate;
  
          this._calStartDate = startDate;
          this._calEndDate = endDate;
  
          while (this._calStartDate.DayOfWeek != DayOfWeek.Sunday)
          {
              this._calStartDate = this._calStartDate.AddDays(-1);
          }
  
          while (this._calEndDate.DayOfWeek != DayOfWeek.Saturday)
          {
              this._calEndDate = this._calEndDate.AddDays(1);
          }
  
      }
  </code></pre>