ASP.NET Calendar - Knowledge Base

« Back to Knowledge Base list

Show the previous month

Q:

I am trying to put three months in the calendar using this:

<obout:Calendar runat="server" Rows="3" Columns="1" />

It is working fine by showing three months from the current month (December 2012): December 2012, January 2013, February 2013.  But I would like to show November 2012, December 2012, January 2013.  Basically previous month, current month and next month.  How do I accomplish this?

A:

You can do it using the code behind:

<script runat="server">
  private void Page_Load(object sender, System.EventArgs e)
  {
      // set the first shown month in the calendar
      Calendar1.DateFirstMonth = Calendar1.DateToday.AddMonths(-1);
  }
</script>

<obout:Calendar ID="Calendar1" runat="server" Rows="3" Columns="1" />