This walkthrough guides you through creating a simple custom data provider control for WebSchedule™ through inheritance. When you subclass an existing data provider, you gain control over much of the data provider’s internal functionality. The procedure below describes data provider fundamentals to get you started.
Before you begin, picture the WebSchedule data provider as a vital organ (like the brain) supplying the WebScheduleInfo control with up-to-date activity, resource, and reminder information that it then pumps (like the heart) to the WebSchedule view controls.
The protected APIs allow you to make many powerful customizations in the data providers including:
Modifying the default database connection string by overriding the ConnectionStringDefault property.
Changing the factory methods that produce a Connection to the database in ADO.NET by overriding the CreateConnection method.
Controlling how Activity and Resource information is channeled to and from your data source by implementing the IDataFetch and IDataUpdate interfaces.
When introducing your own changes into the WebSchedule "central nervous system", your history working with the built-in data providers (and a thorough understanding of the WebSchedule architecture) will help you leverage data provider base class features successfully. While creating your own data provider is powerful, you must also ensure that you do not change behavior that WebSchedule requires to function properly.
Open a new Web Application project in Microsoft® Visual Studio® .NET.
Right-click your solution, and choose "Add New Project …".
From the list of templates, select "Web Control Library" and name your Web control library "CustomProvider". This allows the template project to produce an assembly file named "CustomProvider.dll" as output that you will add to your Web Application project later in step 12.
Add assembly references to the following Infragistics assemblies that the base data provider class depends upon.
Infragistics4.WebUI.Shared.v23.1.dll
Infragistics4.WebUI.WebSchedule.v23.1.dll
Infragistics4.WebUI.WebScheduleDataProvider.v23.1.dll
When creating a custom data provider control as a separate library from your Web application, you must ensure these assemblies have their Copy Local flags set to True.
In Visual Basic .NET you must edit the properties of your "CustomProvider" Web control library to specify a default Root Namespace of "Example". (In C#, this will be handled through the code specified in step 9.)
Open the source file, "WebCustomControl1.vb" (or "WebCustomControl1.cs").
Add the "Infragistics.WebUI.Data" namespace to the top of the source file if it is not already present.
If there is no namespace declaration around the control class, create one. In this example, the namespace, "Example", will be used. A namespace is necessary when registering the TagPrefix (see step 14).
Rename the control class, "CustomDataProvider", and change it to inherit from WebScheduleOleDbProvider. You can erase much of the surplus code that comes in the pre-generated control class, leaving you with the following essential class definition.
In Visual Basic:
<ToolboxData("<{0}:CustomDataProvider runat='server'></{0}:CustomDataProvider>")> _ Public Class CustomDataProvider Inherits WebScheduleOleDbProvider ' Further customizations (constructors, properties, methods) ' you want to make go here. End Class
In C#:
namespace Example { [ToolboxData( "<{0}:CustomDataProvider runat='server'>")] public class CustomDataProvider : WebScheduleOleDbProvider { // Further customizations (constructors, properties, methods) // you want to make go here. } }
In this example, you extend the built-in WebScheduleOleDbProvider control because it provides all the functionality your data provider needs. When subclassing a data provider, take advantage of the most fitting built-in data provider class and focus on which features you want to add or change.
Right-click your Web Custom Control library project in the Solution Explorer window, and select "Build". If your project does not build properly, please review the previous steps in this procedure to ensure the necessary assemblies are referenced and that your source code has not omitted any steps and is error-free.
Right-click in your Web Application project, and select "Add Reference…".
Select the "Projects" tab in which you will add a reference in your Web Application to your Web Custom Control library project containing your CustomDataProvider control.
Open your "WebForm1.aspx" file in Source view.
At the top of the ASPX page, add the following Register directive beneath the Page directive.
<%@ Register TagPrefix="cc" Namespace="Example" Assembly="CustomProvider" %>
Scroll down to the <form> tag and add the following tag for your custom data provider control inside the <form> tag.
<cc:CustomDataProvider runat='server' id='CustomDataProvider1'></cc:CustomDataProvider>
Open your "WebForm1.aspx.vb" (or "WebForm1.aspx.cs") code-behind file by right-clicking your web form ASPX file in the Solution Explorer window and selecting "View Code". Ensure the following line exists. This code declares a CustomDataProvider control, which matches the id attribute value you used in step 15.
In Visual Basic:
Protected WithEvents CustomDataProvider1 As Example.CustomDataProvider
In C#:
protected Example.CustomDataProvider CustomDataProvider1;
If you switch your view of your Web form to Design view, you should see your Custom Data Provider control. Select it, and confirm that all of WebSchedule OLE database provider’s properties are available to you in the Properties window.
Drag and drop a WebScheduleInfo component and any WebSchedule view control onto the design surface from your Toolbox.
Set the WebScheduleInfoID property on the WebSchedule view to "WebScheduleInfo1" to connect it to the WebScheduleInfo component.
Set the WebScheduleInfoID property on your Custom Data Provider control to connect it to the WebScheduleInfo component.
Build and run your Web application using your custom WebSchedule data provider.
In this walkthrough you have successfully created a custom WebSchedule data provider through inheritance. You then used that data provider to connect to WebSchedule information. This basic custom data provider control gives you a foundation to make much more advanced changes to WebSchedule’s data binding.