We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to pass the Collection of Object values to the Schedule control DataSource from the code behind page in ASP.NET?

Platform: ASP.NET Web Forms |
Control: Schedule

You can pass the collection objects to the Schedule control in code behind page.

The following steps help you to pass the collection objects to the Schedule control DataSource from the Code behind page of the ASP.NET application.

Step 1: Refer to the online KB documentation from the following location and add the EJWEB Schedule control to the ASP.NET application.

Step 2: Add the basic schedule rendering code in the design page as shown below

[Default.aspx]

  <ej:Schedule ID="Schedule2" runat="server">
        <AppointmentSettings></AppointmentSettings>
  </ej:Schedule>

Step 3: Now, add the following codes to define various properties of the Schedule control in the code behind page.

[Default.aspx.cs]

protected void Page_Load(object sender, EventArgs e)
        {
            Schedule1.Width = "100%";
            Schedule1.CurrentDate = "05/06/2014";
            Schedule1.AppointmentSettings = new Syncfusion.JavaScript.Models.ScheduleFields() { Id = "ID", Subject = "Subject", AllDay = "AllDay", StartTime = "StartTime", EndTime = "EndTime", Description = "Description", Recurrence = "Recurrence", RecurrenceRule = "RecurrenceRule" };
            // Here you have to map the bind fields to schedule control
            Schedule1.AppointmentSettings.DataSource = GetRecords();// Here, the "GetRecords" method is called to bind the data to schedule control
        }

[Default.aspx.vb]

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Schedule1.Width = "100%"
        Schedule1.CurrentDate = "05/06/2014"
        Schedule1.AppointmentSettings = New Syncfusion.JavaScript.Models.ScheduleFields() With { _
        .Id = "ID", _
        .Subject = "Subject", _
        .AllDay = "AllDay", _
        .StartTime = "StartTime", _
        .EndTime = "EndTime", _
        .Description = "Description", _
        .Recurrence = "Recurrence", _
        .RecurrenceRule = "RecurrenceRule" _
        } ' Here you have to map the bind fields to schedule control
        Schedule1.AppointmentSettings.DataSource = GetRecords()  ' Here, the "GetRecords" method is called to bind the data to schedule control
    End Sub

 

Step 4: Create a class with the required fields to create the object collection. Refer to the following code example to create the class.

[Default.aspx.cs]

[Serializable]
        public class ScheduleAppointmentsObjData
        {
            private int _id;
            private String _subject;
            private String _startTime;
            private String _endTime;
            private String _description;
            private String _owner;
            private Boolean _allDay;
            private Boolean _recurrence;
            private String _recurrenceRule;
            public ScheduleAppointmentsObjData(int _id, string _subject, string _description, string _startTime, string _endTime, string _owner, bool _recurrence, bool _allDay, string _recurrenceRule)
            {
                this._id = _id;
                this._subject = _subject;
                this._startTime = _startTime;
                this._endTime = _endTime;
                this._description = _description;
                this._owner = _owner;
                this._recurrence = _recurrence; ;
                this._allDay = _allDay;
                this._recurrenceRule = _recurrenceRule;
            }
            public int ID
            {
                get
                {
                    return _id;
                }
                set
                {
                    _id = value;
                }
            }
            public string Subject
            {
                get
                {
                    return _subject;
                }
                set
                {
                    _subject = value;
                }
            }
            public string StartTime
            {
                get
                {
                    return _startTime;
                }
                set
                {
                    _startTime = value;
                }
            }
            public string EndTime
            {
                get
                {
                    return _endTime;
                }
                set
                {
                    _endTime = value;
                }
            }
            public string Description
            {
                get
                {
                    return _description;
                }
                set
                {
                    _description = value;
                }
            }
            public string Owner
            {
                get
                {
                    return _owner;
                }
                set
                {
                    _owner = value;
                }
            }
            public Boolean Recurrence
            {
                get
                {
                    return _recurrence;
                }
                set
                {
                    _recurrence = value;
                }
            }
            public Boolean AllDay
            {
                get
                {
                    return _allDay;
                }
                set
                {
                    _allDay = value;
                }
            }
            public string RecurrenceRule
            {
                get
                {
                    return _recurrenceRule;
                }
                set
                {
                    _recurrenceRule = value;
                }
            }
        }

[Default.aspx.vb]

<Serializable> _
    Public Class ScheduleAppointmentsObjData
        Private _id As Integer
        Private _subject As [String]
        Private _startTime As [String]
        Private _endTime As [String]
        Private _description As [String]
        Private _owner As [String]
        Private _allDay As [Boolean]
        Private _recurrence As [Boolean]
        Private _recurrenceRule As [String]
        Public Sub New(_id As Integer, _subject As String, _description As String, _startTime As String, _endTime As String, _owner As String, _
        _recurrence As Boolean, _allDay As Boolean, _recurrenceRule As String)
            Me._id = _id
            Me._subject = _subject
            Me._startTime = _startTime
            Me._endTime = _endTime
            Me._description = _description
            Me._owner = _owner
            Me._recurrence = _recurrence
            Me._allDay = _allDay
            Me._recurrenceRule = _recurrenceRule
        End Sub
        Public Property ID() As Integer
            Get
                Return _id
            End Get
            Set(value As Integer)
                _id = value
            End Set
        End Property
        Public Property Subject() As String
            Get
                Return _subject
            End Get
            Set(value As String)
                _subject = value
            End Set
        End Property
        Public Property StartTime() As String
            Get
                Return _startTime
            End Get
            Set(value As String)
                _startTime = value
            End Set
        End Property
        Public Property EndTime() As String
            Get
                Return _endTime
            End Get
            Set(value As String)
                _endTime = value
            End Set
        End Property
        Public Property Description() As String
            Get
                Return _description
            End Get
            Set(value As String)
                _description = value
            End Set
        End Property
        Public Property Owner() As String
            Get
                Return _owner
            End Get
            Set(value As String)
                _owner = value
            End Set
        End Property
        Public Property Recurrence() As [Boolean]
            Get
                Return _recurrence
            End Get
            Set(value As [Boolean])
                _recurrence = value
            End Set
        End Property
        Public Property AllDay() As [Boolean]
            Get
                Return _allDay
            End Get
            Set(value As [Boolean])
                _allDay = value
            End Set
        End Property
        Public Property RecurrenceRule() As String
            Get
                Return _recurrenceRule
            End Get
            Set(value As String)
                _recurrenceRule = value
            End Set
        End Property
    End Class

Step 5: Define the “GetRecords” method and add the schedule appointment object collection within it. Refer the following code example to add the appointment collection (You can define any number of appointment objects within this method).

[Default.aspx.cs]

[DataObjectMethod(DataObjectMethodType.Select)]
        public List<ScheduleAppointmentsObjData> GetRecords()
        {
            List<ScheduleAppointmentsObjData> list = new List<ScheduleAppointmentsObjData>();
            list.Add(new ScheduleAppointmentsObjData(100, "Bering Sea Gold", "chn", "5/2/2014 9:00:00 AM", "5/2/2014 10:30:00 AM", "1", true, false, "FREQ=DAILY;INTERVAL=2;COUNT=10"));
            list.Add(new ScheduleAppointmentsObjData(101, "Bering Sea Gold", "mum", "5/2/2014 4:00:00 AM", "5/2/2014 5:00:00 AM", "1", false, false, ""));
            list.Add(new ScheduleAppointmentsObjData(102, "Bering Sea Gold", "trcy", "5/2/2014 4:00:00 PM", "5/2/2014 5:30:00 PM", "1", false, false, ""));
            list.Add(new ScheduleAppointmentsObjData(103, "What Happened Next?", "chn", "5/4/2014 3:00:00 AM", "5/4/2014 4:30:00 AM", "1", false, false, ""));
            list.Add(new ScheduleAppointmentsObjData(104, "Bering Sea Gold", "trcy", "5/4/2014 5:00:00 AM", "5/4/2014 5:40:00 AM", "1", false, false, ""));
            list.Add(new ScheduleAppointmentsObjData(105, "Daily Planet", "chn", "5/3/2014 1:00:00 AM", "5/3/2014 2:00:00 AM", "1", false, false, ""));
            list.Add(new ScheduleAppointmentsObjData(106, "Alaska: The Last Frontier", "chn", "5/3/2014 4:00:00 AM", "5/3/2014 5:00:00 AM", "1", false, false, ""));
            list.Add(new ScheduleAppointmentsObjData(107, "How It's Made", "chn", "5/1/2014 6:00:00 AM", "5/1/2014 6:30:00 AM", "1", true, false, "FREQ=WEEKLY;BYDAY=MO,TU;INTERVAL=1;COUNT=15"));
            list.Add(new ScheduleAppointmentsObjData(108, "Deadest Catch", "chn", "5/3/2014 4:00:00 PM", "5/3/2014 5:00:00 PM", "1", false, false, ""));
            list.Add(new ScheduleAppointmentsObjData(109, "MayDay", "chn", "4/30/2014 6:30:00 AM", "4/30/2014 7:30:00 AM", "1", false, false, ""));
            list.Add(new ScheduleAppointmentsObjData(110, "MoonShiners", "chn", "5/2/2014 2:00:00 AM", "5/2/2014 2:30:00 AM", "1", true, false, "FREQ=DAILY;INTERVAL=1;COUNT=5"));
            list.Add(new ScheduleAppointmentsObjData(111, "Close Encounters", "chn", "4/30/2014 2:00:00 PM", "4/30/2014 3:00:00 PM", "1", true, false, "FREQ=WEEKLY;BYDAY=MO,TH;INTERVAL=1;COUNT=5"));
            list.Add(new ScheduleAppointmentsObjData(112, "Close Encounters", "mum", "4/30/2014 3:00:00 AM", "4/30/2014 3:30:00 AM", "1", true, false, "FREQ=WEEKLY;BYDAY=WE;INTERVAL=1;COUNT=3"));
            list.Add(new ScheduleAppointmentsObjData(113, "Highway Thru Hell", "chn", "5/1/2014 3:00:00 AM", "5/1/2014 7:00:00 AM", "1", true, false, "FREQ=DAILY;INTERVAL=2;COUNT=10"));
            list.Add(new ScheduleAppointmentsObjData(114, "Moon Shiners", "chn", "5/2/2014 4:20:00 AM", "5/2/2014 5:50:00 AM", "1", false, false, ""));
            list.Add(new ScheduleAppointmentsObjData(115, "Cash Cab", "chn", "4/30/2014 3:00:00 PM", "4/30/2014 4:30:00 PM", "1", true, false, "FREQ=DAILY;INTERVAL=1;COUNT=5"));
            return list;
        }

[Default.aspx.vb]

<DataObjectMethod(DataObjectMethodType.[Select])> _
    Public Function GetRecords() As List(Of ScheduleAppointmentsObjData)
        Dim list As New List(Of ScheduleAppointmentsObjData)()
        list.Add(New ScheduleAppointmentsObjData(100, "Bering Sea Gold", "chn", "5/2/2014 9:00:00 AM", "5/2/2014 10:30:00 AM", "1", _
        True, False, "FREQ=DAILY;INTERVAL=2;COUNT=10"))
        list.Add(New ScheduleAppointmentsObjData(101, "Bering Sea Gold", "mum", "5/2/2014 4:00:00 AM", "5/2/2014 5:00:00 AM", "1", _
        False, False, ""))
        list.Add(New ScheduleAppointmentsObjData(102, "Bering Sea Gold", "trcy", "5/2/2014 4:00:00 PM", "5/2/2014 5:30:00 PM", "1", _
        False, False, ""))
        list.Add(New ScheduleAppointmentsObjData(103, "What Happened Next?", "chn", "5/4/2014 3:00:00 AM", "5/4/2014 4:30:00 AM", "1", _
        False, False, ""))
        list.Add(New ScheduleAppointmentsObjData(104, "Bering Sea Gold", "trcy", "5/4/2014 5:00:00 AM", "5/4/2014 5:40:00 AM", "1", _
        False, False, ""))
        list.Add(New ScheduleAppointmentsObjData(105, "Daily Planet", "chn", "5/3/2014 1:00:00 AM", "5/3/2014 2:00:00 AM", "1", _
        False, False, ""))
        list.Add(New ScheduleAppointmentsObjData(106, "Alaska: The Last Frontier", "chn", "5/3/2014 4:00:00 AM", "5/3/2014 5:00:00 AM", "1", _
        False, False, ""))
        list.Add(New ScheduleAppointmentsObjData(107, "How It's Made", "chn", "5/1/2014 6:00:00 AM", "5/1/2014 6:30:00 AM", "1", _
        True, False, "FREQ=WEEKLY;BYDAY=MO,TU;INTERVAL=1;COUNT=15"))
        list.Add(New ScheduleAppointmentsObjData(108, "Deadest Catch", "chn", "5/3/2014 4:00:00 PM", "5/3/2014 5:00:00 PM", "1", _
        False, False, ""))
        list.Add(New ScheduleAppointmentsObjData(109, "MayDay", "chn", "4/30/2014 6:30:00 AM", "4/30/2014 7:30:00 AM", "1", _
        False, False, ""))
        list.Add(New ScheduleAppointmentsObjData(110, "MoonShiners", "chn", "5/2/2014 2:00:00 AM", "5/2/2014 2:30:00 AM", "1", _
        True, False, "FREQ=DAILY;INTERVAL=1;COUNT=5"))
        list.Add(New ScheduleAppointmentsObjData(111, "Close Encounters", "chn", "4/30/2014 2:00:00 PM", "4/30/2014 3:00:00 PM", "1", _
        True, False, "FREQ=WEEKLY;BYDAY=MO,TH;INTERVAL=1;COUNT=5"))
        list.Add(New ScheduleAppointmentsObjData(112, "Close Encounters", "mum", "4/30/2014 3:00:00 AM", "4/30/2014 3:30:00 AM", "1", _
        True, False, "FREQ=WEEKLY;BYDAY=WE;INTERVAL=1;COUNT=3"))
        list.Add(New ScheduleAppointmentsObjData(113, "Highway Thru Hell", "chn", "5/1/2014 3:00:00 AM", "5/1/2014 7:00:00 AM", "1", _
        True, False, "FREQ=DAILY;INTERVAL=2;COUNT=10"))
        list.Add(New ScheduleAppointmentsObjData(114, "Moon Shiners", "chn", "5/2/2014 4:20:00 AM", "5/2/2014 5:50:00 AM", "1", _
        False, False, ""))
        list.Add(New ScheduleAppointmentsObjData(115, "Cash Cab", "chn", "4/30/2014 3:00:00 PM", "4/30/2014 4:30:00 PM", "1", _
        True, False, "FREQ=DAILY;INTERVAL=1;COUNT=5"))
        Return list
    End Function

 

Step 6: Run the sample and the Schedule control renders as follows.

schedule control

Figure 1: Schedule control

Sample links

C# Sample

https://www.syncfusion.com/downloads/support/directtrac/general/ScheduleCollectionObjectsCSharp651934581.zip

VB Sample

https://www.syncfusion.com/downloads/support/directtrac/general/ScheduleCollectionObjectsVB1841611264.zip

2X faster development

The ultimate ASP.NET Web Forms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile