How to set an URL binding for Resource datasource in ASP.NET Web Forms Scheduler?
This knowledge base article explains how to set URL binding for resource data source on ASP.NET Web Forms scheduler.
Step 1: Create an ASP.NET Web Forms application with default scheduler code example by referring the below knowledge base link.
https://help.syncfusion.com/aspnet/schedule/getting-started
Also, define the scheduler with Multiple Resources and Grouping option as shown in the below code example.
<ej:Schedule ID="Schedule1" ClientIDMode="Static" Height="525px" Width="100%" EnableLoadOnDemand="true" CurrentDate="3/8/2018" runat="server" > <Resources> <ej:Resources Field="RoomId" Name="Rooms" Title="Room" AllowMultiple="true"> <ResourceSettings Color="Color" Id="Id" Text="Text"> </ResourceSettings> </ej:Resources> <ej:Resources Field="OwnerId" Name="Owners" Title="Owner" AllowMultiple="true"> <ResourceSettings Color="Color" Id="Id" Text="Text" GroupId="GroupId"> </ResourceSettings> </ej:Resources> </Resources> <Group Resources="Rooms,Owners" /> <AppointmentSettings ApplyTimeOffset="false" Id="Id" Subject="Subject" AllDay="AllDay" StartTime="StartTime" StartTimeZone="StartTimeZone" EndTimeZone="EndTimeZone" EndTime="EndTime" Description="Description" Recurrence="Recurrence" RecurrenceRule="RecurrenceRule" ResourceFields="RoomId,OwnerId" /> <DataManager CrossDomain="true" URL="/api/ScheduleWebApi/GetData" CrudURL="/api/ScheduleWebApi/CrudResult" Adaptor="UrlAdaptor"> </DataManager> </ej:Schedule>
Step 2: Now, define the dataSource for Resources by specifying the action names for each resource level within the Page_Load function as shown below.
protected void Page_Load(object sender, EventArgs e) { Schedule1.Resources[0].ResourceSettings.DataSource = "/api/ScheduleWebApi/GetRoomsData"; // Here we are calling the method to get the rooms data Schedule1.Resources[1].ResourceSettings.DataSource = "/api/ScheduleWebApi/GetOwnersData"; // Here we are calling the method to get the owners data }
Step 3: In the API controller file, fetch and return the resource(s) table data collection within the GetRoomsData and GetOwnersData functions as shown below.
ScheduleDataDataContext db = new ScheduleDataDataContext(); [System.Web.Http.ActionName("GetRoomsData")] [AcceptVerbs("GET")] public List<Room> GetRoomsData() { return db.Rooms.ToList(); // Here we getting the rooms details from the database } [System.Web.Http.ActionName("GetOwnersData")] [AcceptVerbs("GET")] public List<Owner> GetOwnersData() { return db.Owners.ToList(); // Here we getting the owner details from the database }
Step 4: Run the sample and the Scheduler will be displayed with the resources data returned from the URL binding actions as follows.
Figure 1: Scheduler displayed with multiple resources.