New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

    Performance

    Appointments loaded from database: 113
    • today
    Monday, April 16, 2012
    • Day
    • Week
    • Month
    • Timeline
    all day
    hola
    this is an APPT.
    terry
    test
    call bob
    dasda
    aaaaaaaaaaaaaaa
    zzzzzzzz
    Show 24 hours...

    This example demonstrates how to optimize the database queries in such way, that only the appointments that for the current view are retrieved. Switch between views and observe the counter.

    When retrieving more than a few appointments from a database it is especially useful to be able to limit the query only to the visible time frame of RadScheduler.

    The VisibleRangeStart and VisibleRangeEnd properties are included to facilitate such optimization.

    Here they are used in conjunction with the parameters of SqlDataSource to avoid retrieving redundant information. This also improves general performance and rendering times.

    Please note that the select query is designed to always retrieve the recurring events. This is necessary as we need to evaluate them in order to determine if they have occurrences in the current time frame.

    • DefaultVB.aspx
    • DefaultVB.aspx.vb
    <%@ Page Language="VB" AutoEventWireup="true" CodeFile="DefaultVB.aspx.vb" Inherits="Scheduler.Examples.OptimizedQueries.DefaultVB" %>
     
    <%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
     
    <!DOCTYPE html>
    <head runat="server">
        <title>Telerik ASP.NET Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadScheduler1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="contentContainer"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="rckbOptimizedQueries">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="contentContainer"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
     
        <div class="demo-container" runat="server" id="contentContainer">
            <telerik:RadCheckBox runat="server" ID="rckbOptimizedQueries" Checked="true" Text="Optimized Queries" OnCheckedChanged="rckbOptimizedQueries_CheckedChanged"></telerik:RadCheckBox>
            <asp:label runat="server" id="AppointmentsCount" style="display:block;"></asp:label>
            <telerik:RadScheduler RenderMode="Lightweight" runat="server" ID="RadScheduler1" SelectedDate="2012-04-16"
                DayStartTime="08:00:00" DayEndTime="18:00:00" DataSourceID="AppointmentsDataSource"
                DataKeyField="ID" DataSubjectField="Subject" DataStartField="Start" DataEndField="End"
                DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentID"
                OverflowBehavior="Auto">
                <AdvancedForm Modal="true"></AdvancedForm>
                <ResourceTypes>
                    <telerik:ResourceType KeyField="ID" Name="Room" TextField="RoomName" ForeignKeyField="RoomID"
                        DataSourceID="RoomsDataSource"></telerik:ResourceType>
                    <telerik:ResourceType KeyField="ID" Name="User" TextField="UserName" ForeignKeyField="UserID"
                        DataSourceID="UsersDataSource"></telerik:ResourceType>
                </ResourceTypes>
                <TimeSlotContextMenuSettings EnableDefault="true"></TimeSlotContextMenuSettings>
                <AppointmentContextMenuSettings EnableDefault="true"></AppointmentContextMenuSettings>
            </telerik:RadScheduler>
        </div>
        <asp:SqlDataSource ID="AppointmentsDataSource" runat="server" OnSelecting="AppointmentsDataSource_Selecting"
            OnSelected="AppointmentsDataSource_Selected" 
            ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString35 %>"
            SelectCommand="SELECT * FROM [Appointments] WHERE ([Start] < @RangeEnd AND [End] > @RangeStart) OR ([RecurrenceRule] <> '') OR ([RecurrenceParentID] IS NOT NULL)"
            InsertCommand="INSERT INTO [Appointments] ([Subject], [Start], [End], [RoomID], [UserID], [RecurrenceRule], [RecurrenceParentID]) VALUES (@Subject, @Start, @End , @RoomID, @UserID, @RecurrenceRule, @RecurrenceParentID)"
            UpdateCommand="UPDATE [Appointments] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [RoomID] = @RoomID, [UserID] = @UserID, [RecurrenceRule] = @RecurrenceRule, [RecurrenceParentID] = @RecurrenceParentID WHERE (ID = @ID)"
            DeleteCommand="DELETE FROM [Appointments] WHERE [ID] = @ID">
            <SelectParameters>
                <asp:Parameter Name="RangeStart" Type="DateTime" DefaultValue="1900/1/1"></asp:Parameter>
                <asp:Parameter Name="RangeEnd" Type="DateTime" DefaultValue="2900/1/1"></asp:Parameter>
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
                <asp:Parameter Name="Subject" Type="String"></asp:Parameter>
                <asp:Parameter Name="Start" Type="DateTime"></asp:Parameter>
                <asp:Parameter Name="End" Type="DateTime"></asp:Parameter>
                <asp:Parameter Name="RoomID" Type="Int32"></asp:Parameter>
                <asp:Parameter Name="UserID" Type="Int32"></asp:Parameter>
                <asp:Parameter Name="RecurrenceRule" Type="String"></asp:Parameter>
                <asp:Parameter Name="RecurrenceParentID" Type="Int32"></asp:Parameter>
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Subject" Type="String"></asp:Parameter>
                <asp:Parameter Name="Start" Type="DateTime"></asp:Parameter>
                <asp:Parameter Name="End" Type="DateTime"></asp:Parameter>
                <asp:Parameter Name="RoomID" Type="Int32"></asp:Parameter>
                <asp:Parameter Name="UserID" Type="Int32"></asp:Parameter>
                <asp:Parameter Name="RecurrenceRule" Type="String"></asp:Parameter>
                <asp:Parameter Name="RecurrenceParentID" Type="Int32"></asp:Parameter>
            </InsertParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="RoomsDataSource" runat="server"
            ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString35 %>"
            SelectCommand="SELECT * FROM [Rooms]">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="UsersDataSource" runat="server"
            ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString35 %>"
            SelectCommand="SELECT * FROM [Users]">
        </asp:SqlDataSource>
        </form>
    </body>
    </html>

    Support & Learning Resources

    Find Assistance