Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD calendar control properties and events - Part 33

Suggested Videos
Part 30 - Fileupload control in
Part 31 - Adrotator control in
Part 32 - calendar control

Useful Properties of the Calendar control
Caption - This is a string read/write property. 
CaptionAlign - Used to align the caption.
DayHeaderStyle - Style properties that can be used to customize the look and feel of the day header in the calendar
DayNameFormat - Can be Full, Short, FirstLetter, FirstTwoLetters, Shortest
DayStyle - Style properties that can be used to customize the look and feel of the day in the calendar
FirstDayOfWeek - Which day of the week is displayed first
NextPrevFormat - Can be ShortMonth, FullMonth, CustomText
NextMonthText - The text to use for the next month button. 
PrevMonthText - The text to use for the previous month button. 
SelectionMode - Can be Day, DayWeek, DayWeekMonth. Determines if Days, Weeks and Months are selectable.

If the SelectionMode is set to Day, then the user can select only one day. In this case to retrieve the selected date, we use SelectedDate property of the calendar as shown below.

However, if the SelectionMode is set to DayWeek or DayWeekMonth. In this case of you want to retrieve all the selected dates within the selected week or month, then SelectedDates property can be used as shown below. Using SelectedDate, property returns only the first selected date of the week or month.
foreach (DateTime selectedDate in Calendar1.SelectedDates)
    Response.Write(selectedDate.ToShortDateString() + "<br/>");

SelectionChanged - Fires when the date,week or Month selection is changed, by the user.
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    foreach (DateTime selectedDate in Calendar1.SelectedDates)
        Response.Write(selectedDate.ToShortDateString() + "<br/>");

DayRender - Fires as a day in the calendar control is being rendered.
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    if (!e.Day.IsOtherMonth && e.Day.Date.Day % 2 == 0)
        e.Cell.Text = "x";
        e.Cell.Font.Bold = true;
        e.Cell.ForeColor = System.Drawing.Color.White;
        e.Cell.BackColor = System.Drawing.Color.Red;
        e.Cell.ToolTip = "Booked";
        e.Cell.ToolTip = "Available";

VisibleMonthChanged - Fires when the visible month is changed by the user
protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
    Response.Write("Month changed from ");
    Response.Write(" to ");
private string GetMonthName(int MonthNumber)
    switch (MonthNumber)
    case 1:
        return "Jan";
    case 2:
        return "Feb";
    case 3:
        return "Mar";
    case 4:
        return "Apr";
    case 5:
        return "May";
    case 6:
        return "Jun";
    case 7:
        return "Jul";
    case 8:
        return "Aug";
    case 9:
        return "Sep";
    case 10:
        return "Oct";
    case 11:
        return "Nov";
    case 12:
        return "Dec";
        return "Invalid Month";


  1. sir,will you please tell me how to insert DATE obtained from a calender in asp to the database.

  2. Hi, When I click the image button - the calendar appears, selection happens properly as well. But when the Calendar appears, other controls placed below it moves down (and after date selection, the other controls move up again).

    I know this is simple, but am stuck here. Please help.


    1. Hi,
      I have the create the same application but nothing out of the ordinary happens. the only change is that when response.write executes, the page aligns to write the response on top. I cant seem to replicate the issue that you are facing

  3. hi Sir
    please tell about the .mdb database connections in

  4. sir, can i get an answer for controlling calendar to select next 4 days from the current date and block rest dates


If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.