KB Article K18278
Visible to All Users

How to print an ASPxScheduler using Reporting mechanism (step-by-step guide)

Description:
To create a printout for the ASPxScheduler, it is necessary to create a report first, and then print it using the ReportViewer Web control. The following steps will guide you in creating a simple report, and previewing it before sending it to a printer.

Answer:
Step 1. Add a Scheduler Report to the Web Site

  1. Open your web site containing an ASPxScheduler control on the main page.
  2. On the Project menu, choose Add New Item… (or press Ctrl+Shift+A) to invoke the Add New Item dialog.
  3. In this dialog, choose the XtraScheduler Report Class v9.2 item, and click Add. This will add a new blank Scheduler report to your application. The Visual Studio shows the designer for the newly created report (by default, it's called XtraSchedulerReport1). The report is derived from the XtraSchedulerReport class, which is the base class for all reports. This is similar to the behavior seen when you're creating a new form class, derived from the base Form class.

Step 2. Construct the Report

  1. To proceed with report creation, open the Toolbox pane (e.g. by pressing CTRL+ALT+X). Then, select the DayViewTimeCells control in the DX.9.2: Report Controls tab and drop it onto the report's DetailBand. The ReportDayView component instance is created automatically, and placed in the component tray.
  2. Add the HorizontalResourceHeaders control. Place it above the DayViewTimeCells control in the Detail Band.
  3. Add the HorizontalDateHeaders control. Place it above the HorizontalResourceHeaders control, and resize it as needed. Its width will determine the width of the time cell area.
  4. Use the smart tag of the HorizontalResourceHeaders control to link it to the HorizontalDateHeaders control. Now, the control is linked to the data provider (ReportDayView) and anchored to date headers.
  5. Use the smart tag of the DayViewTimeCells control to link it to the HorizontalResourceHeaders control.
  6. Add the DayViewTimeRulercontrol, and place it on the left side of the DayViewTimeCells control. Click its smart tag and select the dayViewTimeCells1 control in the DayViewTimeCells drop-down box. The time ruler is linked to the data provider (ReportDayView) and anchored to time cells. Resize it for proper alignment, if necessary, and set the ControlCornersOptions.Top (Top Corner Indent in the smart tag) to 48 pixels - which is the aggregate height of both headers.
  7. Add the TimeIntervalInfo control and the CalendarControl to the Detail Band. Place them above all the controls, at the top of the page. Use the smart tags to link them to the DayViewTimeCells control. The resulting report is shown below.
    You can preview the report by clicking the Preview tab. It uses fake data when previewed in Visual Studio. By default, it is grouped by Resource. You may wish to set the ReportViewBase.GroupType of the ReportDayView component to SchedulerGroupType.None.
    Step 3. Create a Preview Form.
  8. Add a new web user control to the web site using the Add New Item… dialog invoked via the Project menu and selecting the Web Use Control template. Name it ReportPreview.ascx.
  9. Drop the ReportToolbar and ReportViewer controls on a page. Set the ReportToolbar.ReportViewer property value of the ReportToolbar to the ID of the ReportViewer (by default, "ReportViewer1").
    In the code-behind file place the following code:
    C#
     (ReportPreview.ascx.cs)
    using System;
    using DevExpress.XtraScheduler.Reporting;
    using DevExpress.Web.ASPxScheduler.Reporting;
    public partial class ReportPreview : System.Web.UI.UserControl {
        ASPxSchedulerControlPrintAdapter var_controlAdapter;
        public ASPxSchedulerControlPrintAdapter ControlAdapter {
            get { return var_controlAdapter; }
            set { var_controlAdapter = value; } }
        protected void Page_Load(object sender, EventArgs e) {
            XtraSchedulerReport1 rpt = new XtraSchedulerReport1();
            rpt.SchedulerAdapter = ControlAdapter.SchedulerAdapter;
            ReportViewer1.Report = rpt;
        }
    }
    Visual Basic
     (ReportPreview.ascx.vb)
    Imports System
    Imports DevExpress.XtraScheduler.Reporting
    Imports DevExpress.Web.ASPxScheduler.Reporting
    Partial Public Class ReportPreview
        Inherits System.Web.UI.UserControl
        Private var_controlAdapter As ASPxSchedulerControlPrintAdapter
        Public Property ControlAdapter() As ASPxSchedulerControlPrintAdapter
            Get
                Return var_controlAdapter
            End Get
            Set(ByVal value As ASPxSchedulerControlPrintAdapter)
                var_controlAdapter = value
            End Set
        End Property
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim rpt As New XtraSchedulerReport1()
            rpt.SchedulerAdapter = ControlAdapter.SchedulerAdapter
            ReportViewer1.Report = rpt
        End Sub
    End Class
    Step 4. Modify the Main Page.
  10. Place the ASPxPopupControl on a page. Set its ASPxPopupControl.ClientInstanceName to "ASPxPopupControl1". The ASPxPopup control will be used to display a ReportPreview form implemented in the previous steps. Adjust it for better look. For this, set its 2. ASPxPopupControl.PopupHorizontalAlign and ASPxPopupControl.PopupVerticalAlign to PopupHorizontalAlign.WindowCenter and PopupVerticalAlign.WindowCenter respectively. Specify its Height to 680px, and Width - to 600px.
  11. Place the ASPxCallbackPanel into the popup control. Set its ASPxCallbackPanel.ClientInstanceName to "ASPxCallbackPanel1".
  12. Place the System.Web.UI.WebControls.Panel control inside the ASPxCallbackPanel. Set its ID to "PreviewPanel".
  13. Place the ASPxSchedulerControlPrintAdapter control on a page. Set its ASPxSchedulerControlPrintAdapter.SchedulerControl property to the ASPxScheduler control located on the same page.
  14. Specify the ASPxScheduler.ClientInstanceName for the ASPxScheduler on a page as the scheduler.
    Step 5. Add the Code to Display the Report Preview.
  15. In the code-behind file for the main page, add the call to the PrepareReportPreview(PreviewPanel) function in the Page_Load event handler. This function takes the panel located in the ASPxCallbackPanel as the parameter, adjusts the report settings if required, and binds the report to the preview control:
    C#
     (Default.aspx.cs)
        void PrepareReportPreview(Control cp) {
        ASPxSchedulerControlPrintAdapter1.TimeInterval =
            new TimeInterval(DateTime.Today, DateTime.Today.AddDays(7));
        ASPxSchedulerControlPrintAdapter1.WorkTime =
            new TimeOfDayInterval(TimeSpan.FromHours(9), TimeSpan.FromHours(18));
        ReportPreview reportPreview = (ReportPreview)Page.LoadControl("ReportPreview.ascx");
        reportPreview.ControlAdapter = ASPxSchedulerControlPrintAdapter1;
        cp.Controls.Clear();
        cp.Controls.Add(reportPreview);
    }
    Visual Basic
     (Default.aspx.vb)
    Private Sub PrepareReportPreview(ByVal cp As Control)
    ASPxSchedulerControlPrintAdapter1.TimeInterval = New TimeInterval(DateTime.Today, DateTime.Today.AddDays(7))
    ASPxSchedulerControlPrintAdapter1.WorkTime = New TimeOfDayInterval(TimeSpan.FromHours(9), TimeSpan.FromHours(18))
    Dim reportPreview As ReportPreview = CType(Page.LoadControl("ReportPreview.ascx"), ReportPreview)
    reportPreview.ControlAdapter = ASPxSchedulerControlPrintAdapter1
    cp.Controls.Clear()
    cp.Controls.Add(reportPreview)
    End Sub
    Do not forget to include a reference to the custom control in the page's mark up, as follows:
    <%@ Register Src ="~/ReportPreview.ascx" TagName="ReportPreview" TagPrefix="rp" %>
  16. Place a button (the ASPxButton control) on the page. The button will invoke a Preview form. Set the text of the button to "Show Preview". Set its ASPxButton.AutoPostBack property to false. Specify the following code as its Click client-side event handler:
    JScript
    function(s, e) {
        if (_aspxIsExists(window.ClientReportViewer)) {
            scheduler.ShowLoadingPanel();
            window.ClientReportViewer.Refresh();
        }
        else {
            ASPxPopupControl1.Show();
            ASPxCallbackPanel1.PerformCallback();
        }
    }
    Step 6. Run the project (open the web site) and click the button to preview the report
Show previous comments (1)
DevExpress Support Team 6 years ago

    Hi,

    Thank you for your feedback. We will review this article and update it accordingly. At the moment, I recommend that you refer to the How to: Print the ASPxScheduler Using a Report Preview (Step-by-Step Guide) documentation article.

      We're using version 12, so the afore mentioned tutorial doesn't help!

      DevExpress Support Team 6 years ago

        Hello,
        To better process your recent request I've created a separate ticket on your behalf:
        T744020: How to print ASPxScheduler report in version 12
        It has been placed in our processing queue and will be answered shortly.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.