Since I'm just as new to our Scheduler control as some of you, I thought I'd start with a series of posts showing you just how easy it is to do some of the basics! I've gotten several questions already on how to bind the data to the ASP.NET Scheduler control, so we'll start here! :)
First, if you need to create your database to work with our Scheduler, you will need the scripts from this article.
We'll begin with a brand new ASP.NET application, and just drag the ASPxScheduler from the toolbox:
into the MainContent section, then click the arrow on the upper right corner of the ASP.NET Scheduler:
and you'll see the ASPxScheduler Tasks menu. We'll need to set the data source for both appointments and resources (what it is what we're scheduling: people, rooms, equipment, etc.). So, click the data source menu, and choose "<New Data Source>."
This will pop up the Data Source Configuration Wizard:
I'm going to use a SQL Server Compact file, so I click SQL Server, enter a name for the data source, and click OK. Next, I need to create the connection string. So, I click New Connection:
Then, enter the path to the file, and click OK:
Save the connection string to the application, and click Next:
Specify the columns that you will need for your appointments, then click Advanced:
and check "Generate INSERT, UPDATE, and DELETE statements," then click OK.
And click Next, and then Finish. Next, the Mappings Wizard will pop up, and let you verify that the columns that the Scheduler requires are mapped to the columns in your database properly. Required fields are ID, Start, and End. Verify these, and click Next:
Now, you can set the Custom Fields. Choose the additional fields you'd like to include, move them to the right column and, finally, click Finish:
Once that is done, reopen the Tasks menu on the ASPxScheduler, and repeat for the resource data source. If you need to modify the data source at any time, there is an available Tasks menu with a "Configure Data Source…" option which will bring back up the Data Source Configuration Wizard:
One final step to be able to post data back into the database. We need to determine (using SELECT @@IDENTITY), and then assign, the correctly calculated ID value in the INSERT statement. To do this, highlight the data source, then click the InsertQuery property:
to invoke the Command and Parameter Editor:
Now, remove the ID parameter from the INSERT statement text and the parameter list. To generate the correct ID, we'll need to handle a couple events, like so:
protected void ASPxScheduler1_AppointmentRowInserting(object sender,
// Remove unnecessary ID field.
protected void appointmentDataSource_Inserted(object sender,
// Obtain the identity value.
SqlConnection connection = (SqlConnection)e.Command.Connection;
using (SqlCommand cmd = new SqlCommand("SELECT @@IDENTITY", connection))
lastInsertedAppointmentId = (int)cmd.ExecuteScalar();
protected void ASPxScheduler1_AppointmentRowInserted(object sender,
// Specify new ID field value.
e.KeyFieldValue = lastInsertedAppointmentId;
protected void ASPxScheduler1_OnAppointmentsInserted(object sender,
// Store the new appointment.
int count = e.Objects.Count;
System.Diagnostics.Debug.Assert(count == 1);
Appointment apt = (Appointment)e.Objects;
ASPxSchedulerStorage storage = (ASPxSchedulerStorage)sender;
For more information, see Step 13-14 in How to: Bind an ASPxScheduler to Data at Design Time.
And when we run the project, we're good to go!
Hope this helps!
For other data sources and additional examples:
How to bind ASPxScheduler to SQL Server database
How to bind ASPxScheduler to ObjectDataSource
How to bind ASPxScheduler to SyBase ASE 15 database
How to bind ASPxScheduler to LINQ Data Source
How to bind ASPxScheduler with multi-resource appointments to SQL Server database
How to bind ASPxScheduler to XPO via the Unit of Work
For additional documentation: