Click here to Skip to main content
15,879,535 members
Articles / Web Development / HTML

DayPilot - Building an Outlook-Like Calendar Component for ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.86/5 (120 votes)
8 May 2016Apache5 min read 474K   9K   391  
A good-looking ASP.NET control that shows events visually arranged in a day calendar. Includes design-time support and data binding.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DayPilot.Web.Ui;
using DayPilot.Web.Ui.Enums;

public partial class NonBusinessHours : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DayPilotCalendar1.DataSource = getData();
            DataBind();
        }
    }

    ArrayList getData()
    {
        ArrayList al = new ArrayList();

        CustomEvent ce = new CustomEvent();
        ce.Start = Convert.ToDateTime("6:30");
        ce.End = Convert.ToDateTime("19:30");
        ce.Name = "My event";
        ce.Id = "1";

        al.Add(ce);

        return al;

    }

    public class CustomEvent
    {
        private string name;
        private DateTime start;
        private DateTime end;
        private string id;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public DateTime Start
        {
            get { return start; }
            set { start = value; }
        }

        public DateTime End
        {
            get { return end; }
            set { end = value; }
        }

        public string Id
        {
            get { return id; }
            set { id = value; }
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (DropDownList1.SelectedValue)
        {
            case "hide":
                DayPilotCalendar1.HeightSpec = HeightSpecEnum.BusinessHoursNoScroll;
                break;
            case "hideifpossible":
                DayPilotCalendar1.HeightSpec = HeightSpecEnum.Full;
                DayPilotCalendar1.HideFreeCells = true;
                break;
            case "show":
                DayPilotCalendar1.HeightSpec = HeightSpecEnum.Full;
                DayPilotCalendar1.HideFreeCells = false;
                break;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Czech Republic Czech Republic
My open-source event calendar/scheduling web UI components:

DayPilot for JavaScript, Angular, React and Vue

Comments and Discussions