Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Collapse]ASP.NET Controls and MVC Extensions
 [Expand]Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Collapse]ASP.NET WebForms Controls
  [Expand]Reporting
  [Expand]Chart Control
  [Expand]Grid View
  [Expand]Card View
  [Expand]Vertical Grid
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Image and Data Browsing
  [Expand]Docking and Popups
  [Expand]Site Navigation and Layout
  [Expand]File Management
  [Expand]Multi-Use Site Controls
  [Collapse]Scheduler
   [Expand]Product Information
    Getting Started
   [Expand]Fundamentals
   [Expand]Concepts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Collapse]Examples
    [Collapse]Data Binding
      How to: Bind an ASPxScheduler to MS SQL Server Database (Step-by-Step Guide)
      How to: Bind ASPxScheduler to ObjectDataSource
      How to: Filter Appointments
      How to: Bind an ASPxScheduler to XPO via the Unit of Work
      How To: Add Resources to ASPxScheduler Bound to ObjectDataSource
    [Expand]Selection
    [Expand]Customization
    [Expand]Printing and Reporting
    [Expand]Miscellaneous
   [Expand]End-User Capabilities
   [Expand]Member Tables
  [Expand]HTML Editor
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gauges
  [Expand]Data Editors
  [Expand]Spell Checker
  [Expand]Query Builder
 [Expand]ASP.NET MVC Extensions
 [Expand]Localization
 [Expand]Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Bind ASPxScheduler to ObjectDataSource

This document demonstrates how to implement an object data source for use with the ASPxScheduler control.

To create an Object Data Source for appointments and bind it to the ASPxScheduler instance, follow the instructions below.

Expanded Step 1. Create a Web Site

  1. Create a new Web Site in Visual Studio. In the File menu, click New, and then click Web Site. In the New Web Site dialog box that is invoked, click ASP.NET Empty Web Site.
  2. In the Website menu, click Add New Item. Select Web Form, leave the default name as is, and click Add.
  3. Switch to the Design View of the Default.aspx page, and drag the ASPxScheduler control from the DX.17.2: Scheduling Toolbox tab to the page.

Expanded Step 2. Create Classes for the Appointments Object Data Source

  1. In the Website menu, click Add ASP.NET Folder, and then click App_Code.
  2. In the Solution Explorer, right-click the App_Code folder, and then select New | Add New Item.
  3. In the Add New Item dialog box, select the Class template, specify its name as CustomEvents, and click Add. This class will contain all necessary properties for an appointment in the ASPxSchedulerStorage.Appointments collection. The property set is used in standard default mappings when the ASPxSchedulerStorage fetches data from the data source, or the appointment editing form posts data back to the storage.
  4. Create a collection of CustomEvent elements based on a generic System.ComponentModel.BindingList<T> class, which provides data binding.
  5. Provide methods for interaction with the System.Web.UI.WebControls.ObjectDataSource control. The sole purpose of the CustomEventDataSource class is to provide an implementation of the insert, select, delete and update behaviors that will be called by the ObjectDataSource.

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E436.

    This code snippet implements the object data source used for binding to the ASPxScheduler. Note that while other properties of a custom object are mapped in the application to regular appointment properties, the Price and ContactInfo fields should be mapped to appointment's PersistentObject.CustomFields.

Expanded Step 3. Create an ObjectDataSource Control

  1. Switch to the page in which the ASPxScheduler control is located, and drag the ObjectDataSource control from the Data Toolbox tab to the page. Change the ID property of the control to appointmentDataSource.
  2. Click the smart tag of the control, and select the Configure Data Source item. In the Configure Data Source window, select CustomEventDataSource as the business object, and click Next.

  3. In the next panel, select the SelectMethodHandler method from the Choose a method drop-down list.

  4. Switch to the other tabs, and specify the following methods: UpdateMethodHandler for the Update tab, InsertMethodHandler for the Insert tab, and DeleteMethodHandler for the Delete tab. Click Finish.

    The ObjectDataSource is now configured for the CustomEvent objects.

  5. Next, bind the ASPxScheduler to the ObjectDataSource control by setting its AppointmentDataSourceID property to appointmentDataSource in the Property window.

Expanded Step 4. Set Up the Appointment Mappings

  1. Next, set up mappings for the appointments fields. To do this, locate the < dx: ASPxScheduler > opening and closing tags in the Default.aspx file. Add the following code between them:
  2. Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E436.

Expanded Step 5. Implement Methods Required for Proper Binding

  1. To set the appointment ID in the ASPxScheduler storage, create the ASPxScheduler1_AppointmentRowInserted method, which obtains the ID of the last inserted appointment from the object data source, and assigns it to the appointment in the ASPxScheduler storage. To populate the ObjectDataSource control with data, handle the System.Web.UI.WebControls.ObjectDataSource.ObjectCreated event, which is fired when the control is created:

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E436.

  2. Switch to the Design View of the Default.aspx page, and select the ObjectDataSource component. Subscribe the ObjectCreated event to the appointmentsDataSource_ObjectCreated event handler.
  3. Select the ASPxScheduler component. Subscribe the AppointmentRowInserted event to the ASPxScheduler1_AppointmentRowInserted event handler.

Expanded Result

Run the project. Make sure that you can create, delete and edit appointments.

How would you rate this topic?​​​​​​​