This is a migrated thread and some comments may be shown as answers.

RadScheduler Data Binding

4 Answers 195 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Hee
Top achievements
Rank 1
Hee asked on 29 Sep 2011, 03:34 PM
I don't understand RadScheduler.
I want to bind from database. Here is my code. Is that right?
I just want to a basic perform. But I think my code is somewhere That's weird.........
In order to rebind(refresh) every time do I need to call GetSchedule()?
(When I removed "IsPostBack" check, code gives me the "Invalid attempt to call FieldCount when reader is closed" error)
So, what's wrong? please, help me somebody. T-T and forgive my basic English skills.

<body>
    <form id="form1" runat="server">
    <div class="telerikControls">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" OutputCompression="Disabled">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script language="javascript" type="text/javascript">
            </script>
        </telerik:RadCodeBlock>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadSchedulerTemplate">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadSchedulerTemplate" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadSchedulerTemplate" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadButtonNewAppointment">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadSchedulerTemplate" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
    </div>
    <div>
        <table width="100%">
            <tr>
                <td align="right">
                    <telerik:RadButton ID="RadButtonNewAppointment" runat="server" EnableEmbeddedSkins="true" Skin="Default" Text="New" Width="60" />
                </td>
            </tr>
            <tr>
                <td>
                    <telerik:RadScheduler ID="RadSchedulerTemplate" runat="server"
                        EnableDescriptionField="true" Height="800"
                        SelectedView="DayView" DataKeyField="ID" DataSubjectField="Subject" DataStartField="Start" DataEndField="End"
                        DataDescriptionField="Description" DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentID"
                        DataReminderField="Reminder">
                        <AdvancedForm Modal="true" />
                        <Reminders Enabled="true" />
                        <AppointmentContextMenuSettings EnableDefault="true" />
                        <TimeSlotContextMenuSettings EnableDefault="true" />
                    </telerik:RadScheduler>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>


Private Sub _RadSchedulerDefault_Init(sender As Object, e As System.EventArgs) Handles Me.Init
    If Not IsPostBack Then
        GetSchedule()
    End If
End Sub
 
Private Sub GetSchedule()
    Dim sqlCommand As SqlCommand = New SqlCommand
 
    Try
        _sqlConnection.ConnectionString = DBConnectionManager.OpenConnection()
        sqlCommand = _sqlConnection.CreateCommand
        sqlCommand.CommandType = CommandType.StoredProcedure
        sqlCommand.CommandText = "S_01"
        _sqlDataReader = sqlCommand.ExecuteReader
        RadSchedulerTemplate.DataSource = _sqlDataReader
    Catch ex As Exception
        DBConnectionManager.CloseConnection(_sqlConnection, _sqlDataReader)
    Finally
        DBConnectionManager.CloseConnection(sqlCommand)
    End Try
End Sub

Private Sub RadSchedulerTemplate_DataBound(sender As Object, e As System.EventArgs) Handles RadSchedulerTemplate.DataBound
    DBConnectionManager.CloseConnection(_sqlConnection, _sqlDataReader)
End Sub

Private Sub RadSchedulerTemplate_AppointmentInsert(sender As Object, e As Telerik.Web.UI.AppointmentInsertEventArgs) Handles RadSchedulerTemplate.AppointmentInsert
    Dim dbConnection As SqlConnection = New SqlConnection
    Dim dbCommand As SqlCommand = New SqlCommand
 
    Try
        Dim app As Appointment = e.Appointment
        Dim subject As String = app.Subject
        Dim startDate As DateTime = app.Start
        Dim endDate As DateTime = app.End
        Dim recurrenceRule As String = app.RecurrenceRule
        Dim recurrenceParentID As Integer = app.RecurrenceParentID
        Dim description As String = app.Description
        Dim reminder As String = app.Reminders.ToString
        dbConnection = DBConnectionManager.OpenConnection()
        dbCommand = dbConnection.CreateCommand
        dbCommand.CommandType = CommandType.StoredProcedure
        dbCommand.CommandText = "S_02"
        dbCommand.Parameters.Add("@Subject", SqlDbType.VarChar).Value = subject
        dbCommand.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = startDate
        dbCommand.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = endDate
        If Not String.IsNullOrEmpty(recurrenceRule) Then
            dbCommand.Parameters.Add("@RecurrenceRule", SqlDbType.VarChar).Value = recurrenceRule
        End If
        If recurrenceParentID <> 0 Then
            dbCommand.Parameters.Add("@RecurrenceParentID", SqlDbType.Int).Value = recurrenceParentID
        End If
        If Not String.IsNullOrEmpty(description) Then
            dbCommand.Parameters.Add("@Description", SqlDbType.VarChar).Value = description
        End If
        If Not String.IsNullOrEmpty(reminder) Then
            dbCommand.Parameters.Add("@Reminder", SqlDbType.VarChar).Value = reminder
        End If
        dbCommand.ExecuteNonQuery()
        GetSchedule()
    Catch ex As Exception
    'exception
    Finally
        DBConnectionManager.CloseConnection(dbConnection, Nothing, dbCommand)
    End Try
End Sub
 
Private Sub RadSchedulerTemplate_NavigationCommand(sender As Object, e As Telerik.Web.UI.SchedulerNavigationCommandEventArgs) Handles RadSchedulerTemplate.NavigationCommand
    GetSchedule()
End Sub

4 Answers, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 04 Oct 2011, 08:42 AM
Hello Hee,

I have made a sample web page for you which shows how to bind the RadScheduler to a database.

Attached are the aspx, aspx.cs files and the App_Data folder which contains the database.

Also you could use the smart tag of the RadScheduler to bind it to a database. Here is an help article which shows how to do it.
You could also refer to the data binding section of the RadScheduler at the following link at our website:
RadScheduler: DataBInding
.

Hope this helps.

Regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Hee
Top achievements
Rank 1
answered on 04 Oct 2011, 08:53 AM
Thanks for your reply.
But...I want to manually binding. I don't want to use SqlDataSource...

0
Ivana
Telerik team
answered on 06 Oct 2011, 12:45 PM
Hello Hee,

Take a look at the following demo: RadScheduler: Binding to a Generic List. It shows the logic of binding to a data source from code-behind.

If you are still having troubles, could you send us a support ticket where a sample page with the problem isolated in it could be attached. Please use some dummy database in the sample, so we can run and examine it locally. Thank you.


Greetings, Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Marcel Härry
Top achievements
Rank 1
answered on 26 Jun 2012, 09:37 AM
Never thought it's so easy. It's really fun...Thanks a lot for the sample.
Tags
Scheduler
Asked by
Hee
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Hee
Top achievements
Rank 1
Marcel Härry
Top achievements
Rank 1
Share this question
or