In this tutorial we will learn to use the calender control and display the selected dates in the calender control.

ASP.net Calaneder Control

Let’s add a new form to our ASP .NET website and name it CalendexExample.aspx . See to it that you allow the addition of a code behind file.  From the ToolBox in the sidebar of the IDE (Visual Studio 2013) find the Calender Control and drag and drop it to the design view.

CalenderControlTutorialby

If you are the code guy then feel free to add the following code to the code view of the page between the <div></div> tags.

We will be using the following controls for this simple example:

  1. Calender Control
  2. Button Control
  3. Bulleted List Control
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CalenderExample.aspx.cs" Inherits="CalenderExample" %>
<%– Add the calender control here. We will use this
interface for the user to select the dates he is interested in –%>
<%– Add the submit button to get the list of selected dates –%>


<%– Add the bulleted list of ASP to display the selected dates on the click of
the submited button –%>

 

In the code behind file we will add the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CalenderExample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //assign the salected dates of the calender control 
        //as the data source of the bulleted list.
        bltselectedDate.DataSource = Calendar1.SelectedDates;
        //Bind the data source to the bulleted list
        bltselectedDate.DataBind();
    }
}