Click here to Skip to main content
15,891,136 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 475.5K   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.IO;
using System.Reflection;
using DayPilot.Web.Ui;

public partial class Demo : System.Web.UI.MasterPage
{
    //private string root;

    protected void Page_Load(object sender, EventArgs e)
    {
	// prevent invalid ViewState errors in Firefox
        if (Request.Browser.Browser == "Firefox") Response.Cache.SetNoStore();

        if (!IsPostBack)
        {
            Repeater1.DataBind();
            Repeater2.DataBind();
        }
    }

    protected bool MenuVisible
    {
        get
        {
            return root != ResolveUrl("~/");
        }
    }

    private string root
    {
        get
        {
            return Request.FilePath.Substring(0, Request.FilePath.LastIndexOf('/')) + "/";
        }
    }
    private DataTable tabs = null;
    protected DataTable Tabs
    {
        get
        {
            if (tabs == null)
            {
                DataSet ds = new DataSet();
                ds.ReadXml(Server.MapPath("~/Navigation.config"));
                DataTable dt = ds.Tables["Item"];

                foreach (DataRow r in dt.Rows)
                {
                    string url = r["url"] as string;

                    if (url == null)
                        continue;

                    r["url"] = ResolveUrl("~" + url);

                    if (root == ResolveUrl("~" + url))
                    {
                        r["class"] = "tab selected";
                    }
                    else
                    {
                        r["class"] = "tab";
                    }

                    //r["url"] = normalized;
                }
                tabs = dt;
            }

            return tabs;

        }
    }

    protected string Description
    {
        get
        {
            DataTable dt = LocalNavigation.Tables["Description"];
            if (dt == null || dt.Rows.Count == 0)
            {
                return String.Empty;
            }
            return dt.Rows[0]["text"] as string;
        }
        
    }

    private DataSet localNavigation;
    private DataSet LocalNavigation
    {
        get
        {
            if (localNavigation == null)
            {
                localNavigation = new DataSet();
                localNavigation.ReadXml(Server.MapPath("Navigation.config"));
            }
            return localNavigation;
        }
    }

    protected DataTable Items
    {
        get
        {
            DataTable dt = LocalNavigation.Tables["Item"].Copy();

            foreach (DataRow r in dt.Rows)
            {
                string url = r["url"] as string;

                if (url == null)
                    continue;

                if (Request.Path.ToUpper().IndexOf("/" + url.ToUpper()) != -1)
                {
                    r["url"] = ResolveUrl(root + url);
                    r["class"] = "selected";
                }
                else
                {
                    r["url"] = ResolveUrl(root + url);
                    r["class"] = "";
                }
            }
            return dt;

        }
    }

    protected bool IsSandbox
    {
        get
        {
            return Request.Path.ToLower().Contains("sandbox");
        }
    }

    protected bool IsDemo
    {
        get
        {
            return Request.Path.ToLower().Contains("demo");
        }
    }

}

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