Tutorial: ASP.NET Scheduler with On-Demand AJAX Event Loading

This ASP.NET tutorial shows how to configure the scheduler control to load events from the server side using an AJAX call during scrolling (on-demand). Includes sample C# an VB.NET Visual Studio projects.
Jul 2, 2014
asp.net scheduler with on demand loading

Tutorial

Features

  • Large data set (25,000) events
  • Loading data for the current viewport during scrolling
  • Configurable cache/buffer sweeping
  • Configurable cache/buffer size
  • Sample Visual Studio 2012 project with source code (C# and VB.NET)
  • Sample Microsoft SQL Server database (LocalDB)
  • The sample project includes a trial version of DayPilot Pro for ASP.NET WebForms package.

Example

Sample configuration and AJAX loading code:

.aspx

<DayPilot:DayPilotScheduler 
  ...
  DynamicLoading="true"
  OnScroll="Scheduler_OnScroll"

  />

.aspx.cs

protected void Scheduler_OnScroll(object sender, ScrollEventArgs e)
{
  SetDataSourceAndBind(Scheduler.ViewPort.Start, Scheduler.ViewPort.End);
  Scheduler.Update();
}

private void SetDataSourceAndBind(DateTime start, DateTime end)
{
  Scheduler.DataSource = GetData(start, end);
  Scheduler.DataStartField = "eventstart";
  Scheduler.DataEndField = "eventend";
  Scheduler.DataIdField = "id";
  Scheduler.DataTextField = "name";
  Scheduler.DataResourceField = "resource_id";
  Scheduler.DataBind();

}

private DataTable GetData(DateTime start, DateTime end)
{
  SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM [event] WHERE NOT (([eventend] <= @start) OR ([eventstart] >= @end))", ConfigurationManager.ConnectionStrings["daypilot"].ConnectionString);
  da.SelectCommand.Parameters.AddWithValue("start", start);
  da.SelectCommand.Parameters.AddWithValue("end", end);

  DataTable dt = new DataTable();
  da.Fill(dt);

  return dt;
}

The source code of the tutorial is available for download.