INTRODUCTION
In this article ,you will learn to use Javascript Calendar in your project
Let's start.
STEP 1
Open Visual Studio 2010 => Click New Project => Select ASP.NET Web Application => Fill all required details.
Step 2
Delete all auto generated files and add below file
- AngularJS Folder
- CSS Folder
- HTML Folder
- JS Folder
- Plugin Folder
- Dashboard.aspx
- DetailView.aspx
Step 3
Download project and add
- angular.js plugin and app.js in AngularJS Folder
- main.css in CSS Folder
- main.js in Plugin Folder
Step 4
Replace auto generated Dashboard.htm code with the below code.
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" data-ng-app="app">
- <head>
- <title>Calendar Demo</title>
- <link href='../CSS/main.css' rel='stylesheet' />
- <script src='../Plugin/main.js' type="text/javascript"></script>
- <script src="../AngularJS/angular.js" type="text/javascript"></script>
- <script src="../AngularJS/app.js" type="text/javascript"></script>
- <script src="../JS/DashboardCtrl.js" type="text/javascript"></script>
-
- <style type="text/css">
- html, body
- {
- overflow: hidden;
- font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
- font-size: 12px;
- }
- #calendar-container
- {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- }
- .fc-header-toolbar
- {
-
-
-
-
- padding-top: 1em;
- padding-left: 1em;
- padding-right: 1em;
- }
- </style>
- </head>
- <body ng-controller="DashBoardCtrl">
- <div id="loader" style="display: none;">
- </div>
- <div id='calendar-container'>
- <div id='calendar'>
- </div>
- </div>
- </body>
- </html>
Step 5
Paste the below Script code in DashboardCtrl.js.
Note
Here I am hardcoded Calendar data in js file , you can use Web Service / WCF Service / Web API.
- var calendardata = [];
-
- var app = angular.module('app').controller('DashBoardCtrl', ['$scope', function ($scope) {
-
- $scope.lstDashBoarddata = [
- {
- "CRITICALITY": "DONE",
- "CNT": "1",
- "DUEDATE": "2021-04-05"
- },
- {
- "CRITICALITY": "DONE",
- "CNT": "1",
- "DUEDATE": "2021-04-06"
- },
- {
- "CRITICALITY": "DONE",
- "CNT": "2",
- "DUEDATE": "2021-04-07"
- },
- {
- "CRITICALITY": "DONE",
- "CNT": "1",
- "DUEDATE": "2021-04-08"
- },
- {
- "CRITICALITY": "OVERDUE",
- "CNT": "2",
- "DUEDATE": "2021-04-05"
- },
- {
- "CRITICALITY": "OVERDUE",
- "CNT": "1",
- "DUEDATE": "2021-04-06"
- },
- {
- "CRITICALITY": "OVERDUE",
- "CNT": "1",
- "DUEDATE": "2021-04-07"
- },
- {
- "CRITICALITY": "OVERDUE",
- "CNT": "1",
- "DUEDATE": "2021-04-08"
- },
- {
- "CRITICALITY": "PENDING",
- "CNT": "1",
- "DUEDATE": "2021-04-15"
- },
- {
- "CRITICALITY": "PENDING",
- "CNT": "2",
- "DUEDATE": "2021-04-16"
- }
- ]
-
-
- calendardata = [];
-
- $scope.GetDashboardList = function () {
-
- for (var i = 0; i < $scope.lstDashBoarddata.length; i++) {
- if ($scope.lstDashBoarddata[i].CRITICALITY == "DONE") {
- calendardata.push({ "title": $scope.lstDashBoarddata[i].CRITICALITY + '(' + $scope.lstDashBoarddata[i].CNT + ')', "start": $scope.lstDashBoarddata[i].DUEDATE, "url": "../DetailView.aspx?Date= " + $scope.lstDashBoarddata[i].DUEDATE + "&Criticality=DONE", color: 'green' });
- }
- if ($scope.lstDashBoarddata[i].CRITICALITY == "OVERDUE") {
- calendardata.push({ "title": $scope.lstDashBoarddata[i].CRITICALITY + '(' + $scope.lstDashBoarddata[i].CNT + ')', "start": $scope.lstDashBoarddata[i].DUEDATE, "url": "../DetailView.aspx?Date= " + $scope.lstDashBoarddata[i].DUEDATE + "&Criticality=OVERDUE", color: 'red' });
- }
- if ($scope.lstDashBoarddata[i].CRITICALITY == "PENDING") {
- calendardata.push({ "title": $scope.lstDashBoarddata[i].CRITICALITY + '(' + $scope.lstDashBoarddata[i].CNT + ')', "start": $scope.lstDashBoarddata[i].DUEDATE, "url": "../DetailView.aspx?Date= " + $scope.lstDashBoarddata[i].DUEDATE + "&Criticality=PENDING", color: 'orange' });
- }
- }
-
- var calendarEl = document.getElementById('calendar');
-
- var todaydate = new Date();
-
- var calendar = new FullCalendar.Calendar(calendarEl, {
- height: '100%',
- expandRows: true,
- initialView: 'dayGridMonth',
- initialDate: todaydate,
- editable: true,
- selectable: true,
- businessHours: true,
- dayMaxEvents: true,
-
- events: calendardata
-
- });
-
- calendar.render();
- }
-
- $scope.GetDashboardList();
-
- } ]);
Step 6
Paste the below Html code in Dashboard.aspx under the body tag.
- <form id="form1" runat="server">
- <div>
- <iframe src ="HTML/Dashboard.htm" height = "550px" width = "100%"></iframe>
- </div>
- </form>
Step 7
Paste the below Html code in DetailView.aspx under the body tag.
- <form id="form1" runat="server">
- <div>
- <asp:GridView ID="gvdetailview" runat="server" BackColor="#DEBA84"
- BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3"
- CellSpacing="2">
- <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
- <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
- <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
- <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
- <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
- <SortedAscendingCellStyle BackColor="#FFF1D4" />
- <SortedAscendingHeaderStyle BackColor="#B95C30" />
- <SortedDescendingCellStyle BackColor="#F1E5CE" />
- <SortedDescendingHeaderStyle BackColor="#93451F" />
- </asp:GridView>
- </div>
- </form>
Step 8
Replace auto generated DetailView.aspx.cs class code with the below code.
Note
Here I am hardcoded DetailView data in class file , you can use Database.
- public partial class DetailView : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- string date = Request.QueryString["Date"];
- string criticality = Request.QueryString["Criticality"];
-
- GetDetailData(date, criticality);
- }
-
- }
-
- public void GetDetailData(string date,string criticality)
- {
- DataTable dtDetails = new DataTable();
-
- dtDetails.Columns.Add("TASKNAME", typeof(String));
- dtDetails.Columns.Add("DUEDATE", typeof(DateTime));
- dtDetails.Columns.Add("CRITICALITY", typeof(String));
- dtDetails.Columns.Add("STATUS", typeof(String));
-
- DataRow dr = dtDetails.NewRow();
- dr["TASKNAME"] = "TASK 1";
- dr["DUEDATE"] = "2021-04-05";
- dr["CRITICALITY"] = "DONE";
- dr["STATUS"] = "Completed";
-
- DataRow dr1 = dtDetails.NewRow();
- dr1["TASKNAME"] = "TASK 2";
- dr1["DUEDATE"] = "2021-04-06";
- dr1["CRITICALITY"] = "DONE";
- dr1["STATUS"] = "Cmpleted";
-
- DataRow dr2 = dtDetails.NewRow();
- dr2["TASKNAME"] = "TASK 3";
- dr2["DUEDATE"] = "2021-04-07";
- dr2["CRITICALITY"] = "DONE";
- dr2["STATUS"] = "Completed";
-
- DataRow dr3 = dtDetails.NewRow();
- dr3["TASKNAME"] = "Task 4";
- dr3["DUEDATE"] = "2021-04-07";
- dr3["CRITICALITY"] = "DONE";
- dr3["STATUS"] = "Completed";
-
- DataRow dr4 = dtDetails.NewRow();
- dr4["TASKNAME"] = "Task 5";
- dr4["DUEDATE"] = "2021-04-08";
- dr4["CRITICALITY"] = "DONE";
- dr4["STATUS"] = "Completed";
-
- DataRow dr5 = dtDetails.NewRow();
- dr5["TASKNAME"] = "Task 6";
- dr5["DUEDATE"] = "2021-04-05";
- dr5["CRITICALITY"] = "OVERDUE";
- dr5["STATUS"] = "Pending with EmployeeID #1";
-
- DataRow dr6 = dtDetails.NewRow();
- dr6["TASKNAME"] = "Task 7";
- dr6["DUEDATE"] = "2021-04-05";
- dr6["CRITICALITY"] = "OVERDUE";
- dr6["STATUS"] = "Pending with EmployeeID #2";
-
- DataRow dr7 = dtDetails.NewRow();
- dr7["TASKNAME"] = "Task 8";
- dr7["DUEDATE"] = "2021-04-06";
- dr7["CRITICALITY"] = "OVERDUE";
- dr7["STATUS"] = "Pending with EmployeeID #3";
-
- DataRow dr8 = dtDetails.NewRow();
- dr8["TASKNAME"] = "Task 9";
- dr8["DUEDATE"] = "2021-04-07";
- dr8["CRITICALITY"] = "OVERDUE";
- dr8["STATUS"] = "Pending with EmployeeID #4";
-
- DataRow dr9 = dtDetails.NewRow();
- dr9["TASKNAME"] = "Task 10";
- dr9["DUEDATE"] = "2021-04-08";
- dr9["CRITICALITY"] = "OVERDUE";
- dr9["STATUS"] = "Pending with EmployeeID #5";
-
- DataRow dr10 = dtDetails.NewRow();
- dr10["TASKNAME"] = "Task 11";
- dr10["DUEDATE"] = "2021-04-15";
- dr10["CRITICALITY"] = "PENDING";
- dr10["STATUS"] = "Pending with EmployeeID #6";
-
- DataRow dr11 = dtDetails.NewRow();
- dr11["TASKNAME"] = "Task 12";
- dr11["DUEDATE"] = "2021-04-16";
- dr11["CRITICALITY"] = "PENDING";
- dr11["STATUS"] = "Pending with EmployeeID #7";
-
- DataRow dr12 = dtDetails.NewRow();
- dr12["TASKNAME"] = "Task 13";
- dr12["DUEDATE"] = "2021-04-16";
- dr12["CRITICALITY"] = "PENDING";
- dr12["STATUS"] = "Pending with EmployeeID #8";
-
- dtDetails.Rows.Add(dr);
- dtDetails.Rows.Add(dr1);
- dtDetails.Rows.Add(dr2);
- dtDetails.Rows.Add(dr3);
- dtDetails.Rows.Add(dr4);
- dtDetails.Rows.Add(dr5);
- dtDetails.Rows.Add(dr6);
- dtDetails.Rows.Add(dr7);
- dtDetails.Rows.Add(dr8);
- dtDetails.Rows.Add(dr9);
- dtDetails.Rows.Add(dr10);
- dtDetails.Rows.Add(dr11);
- dtDetails.Rows.Add(dr12);
-
- DataTable finaldt = new DataTable();
-
- finaldt.Columns.Add("TASKNAME", typeof(String));
- finaldt.Columns.Add("DUEDATE", typeof(String));
- finaldt.Columns.Add("CRITICALITY", typeof(String));
- finaldt.Columns.Add("STATUS", typeof(String));
-
- DataRow[] drfinalrow = dtDetails.Select("DUEDATE = '" + date + "' AND CRITICALITY = '" + criticality + "'");
-
- DataRow NewRow;
-
- foreach (DataRow row in drfinalrow)
- {
- NewRow = finaldt.NewRow();
- NewRow["TASKNAME"] = row["TASKNAME"];
- NewRow["DUEDATE"] = Convert.ToDateTime(row["DUEDATE"]).ToString("dd-MM-yyyy");
- NewRow["CRITICALITY"] = row["CRITICALITY"];
- NewRow["STATUS"] = row["STATUS"];
- finaldt.Rows.Add(NewRow);
- }
-
- gvdetailview.DataSource = finaldt;
- gvdetailview.DataBind();
-
- }
-
- }
Step 9
Run Application you can see calendar view displayed based on date
Step 10
Click any category (DONE / OVERDUE / PENDING)
I am clicked 07-04-2021 DONE category
Click on any Overdue category
Click on Pending category
I hope this helps.
Thank you.