How to: Create an Appointment for the Currently Selected Time Interval and Resource

  • 2 minutes to read

Before trying to create an appointment in code at runtime, make sure that the ASPxScheduler Control is bound to data, and all mappings for the appointments and resources are correct. To learn how the data binding task for the ASPxScheduler can be accomplished, refer to the following topics: How to: Bind an ASPxScheduler to MS SQL Server Database (Step-by-Step Guide) and How to: Bind ASPxScheduler Appointment to ObjectDataSource.

This example demonstrates how to create a new appointment for the time interval currently selected in the scheduler. It takes into account the resource which contains the selected time interval, and sets its Id to the appointment. The selected time interval is accessed via the SchedulerViewBase.SelectedInterval property, and the selected resource is accessed via the ASPxScheduler.SelectedResource property. An appointment is added to the ASPxSchedulerStorage.Appointments collection of the scheduler's ASPxSchedulerDataWebControlBase.Storage.

using DevExpress.XtraScheduler;
using DevExpress.Web.ASPxScheduler;
// ...

// Create a new appointment.
Appointment apt = new Appointment();

// Set the appointment's time interval to the time interval
// currently selected by an end-user.
apt.Start = ASPxScheduler1.SelectedInterval.Start;
apt.End = ASPxScheduler1.SelectedInterval.End;

// Set the appointment's resource to the resource which contains
// the currently selected time interval.
apt.ResourceId = ASPxScheduler1.SelectedResource.Id;

// Add the new appointment to the appointment collection.