title: Asp.net Calendar How to
body: <p>I have a question about a project where I am working on 
  it is a calendar where you can put a comment to a special day / year</p>
  
  <p>I'm using atm the asp.net calendar control.</p>
  
  <p>Here is the image of this idea:</p>
  
  <p><img src="https://i.stack.imgur.com/bm9JT.jpg" alt="http://i.stack.imgur.com/AkSk9.jpg"></p>
  
  <p>Here is the Markup code:</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true"  MasterPageFile="~/Calender.master" CodeFile="Calender.aspx.cs" Inherits="_Default" %&gt;
  
  &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"&gt;
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
  &lt;form id="Form1" runat="server"&gt;
  &lt;asp:ScriptManager ID="SM1" runat="server" /&gt;
  &lt;asp:UpdatePanel ID="UP1" runat="server"&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:Calendar ID="Calendar1" ShowGridLines="true" CellPadding="15"  runat="server"
              OnDayRender="Calendar1_DayRender"  OnSelectionChanged="Calendar1_SelectionChanged  "&gt;
  
              &lt;/asp:Calendar&gt;
          &lt;br /&gt;
          &lt;asp:FormView ID="FormView1" runat="server" AllowPaging="true"
              DataKeyNames="date" DataSourceID="todoSrc" DefaultMode="Edit"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:Label ID="lblTodo" runat="server" AssociatedControlID="txtTodo" Text="Afspraak:" /&gt;
                  &lt;br /&gt;
                  &lt;asp:TextBox ID="txtTodo" runat="server" TextMode="MultiLine" Columns="30" Rows="5"
                      Text="&lt;%# Bind('todo') %&gt;"&gt;&lt;/asp:TextBox&gt;
                      &lt;br /&gt;&lt;br /&gt;
  
                  &lt;asp:LinkButton ID="butUpdate" runat="server" Text="Update" CommandName="Update" /&gt;
              &lt;/EditItemTemplate&gt;
              &lt;InsertItemTemplate&gt;
                  &lt;asp:Label ID="lblTodo" runat="server" Text="Toevoegen:" AssociatedControlID="txtTodo" /&gt;
                  &lt;br /&gt;
                  &lt;asp:TextBox ID="txtTodo" runat="server" Text="&lt;%# Bind('todo') %&gt;" TextMode="MultiLine"
                      Columns="30" Rows="5" /&gt;
                  &lt;br /&gt;
                  &lt;asp:Button ID="butInsert" runat="server"  Text="Add" CommandName="Insert" /&gt;
              &lt;/InsertItemTemplate&gt;
          &lt;/asp:FormView&gt;
          &lt;br /&gt;
          &lt;asp:Button ID="butAddNew" runat="server" Text="Toevoegen" OnClick="butAddNew_Click" /&gt;
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt; 
  &lt;SelectParameters&gt;
  &lt;asp:SqlDataSource ID="todoSrc" runat="server" ConnectionString="&lt;%$ ConnectionStrings:Stefan %&gt;"
      DeleteCommand="DELETE Calender WHERE date=@date" InsertCommand="INSERT Calender (date,todo) VALUES (@date,@todo)"
      SelectCommand="SELECT * FROM Calender WHERE date=@date" UpdateCommand="UPDATE Calender SET todo=@todo WHERE date=@date"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:ControlParameter Name="date" ControlID="Calendar1" PropertyName="SelectedDate" /&gt;
      &lt;/SelectParameters&gt;
      &lt;InsertParameters&gt;
          &lt;asp:ControlParameter Name="date" ControlID="Calendar1" PropertyName="SelectedDate" /&gt;
      &lt;/InsertParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  &lt;asp:SqlDataSource ID="calendarSrc" runat="server" ConnectionString="&lt;%$ ConnectionStrings:Stefan %&gt;"
      SelectCommand="SELECT date FROM Calender"&gt;&lt;/asp:SqlDataSource&gt;
      &lt;/form&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>And here is the Codebehind cs file</p>
  
  <pre><code>using System;
  using System.Configuration;
  using System.Data;
  using System.Linq;
  using System.Web;
  using System.Web.Security;
  using System.Web.UI;
  using System.Web.UI.HtmlControls;
  using System.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;
  using System.Data.SqlClient;
  using System.Collections;
  
  public partial class _Default : System.Web.UI.Page
  {
  
  
      DataView todo = new DataView();
  
      protected void Page_Load(object sender, EventArgs e)
      {
  
          if (Calendar1.SelectedDate == DateTime.MinValue)
              Calendar1.SelectedDate = Calendar1.TodaysDate;
      }
  
  
      void Page_PreRender()
      {
          todo = (DataView)calendarSrc.Select(DataSourceSelectArguments.Empty);
          todo.Sort = "date";
  
  
      }
  
      protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
      {
          if (todo.FindRows(e.Day.Date).Length &gt; 0)
              e.Cell.BackColor = System.Drawing.Color.Aqua;
  
      }
  
      protected void Calendar1_SelectionChanged(object sender, EventArgs e)
      {
          FormView1.ChangeMode(FormViewMode.Edit);
  
      }
  
      protected void butAddNew_Click(object sender, EventArgs e)
      {
          FormView1.ChangeMode(FormViewMode.Insert);
  
  
      }
  
  
  }
  </code></pre>