Blogs

DevExpress Data Blog

This blog features all things having to do with data shaping, layout, and presentation!

August 2011 - Posts

  • ASP.NET Reporting - An Important Change in the Client-Server Interaction of Report Viewer

    This blog post details some changes made in the v2011 vol 1 version of our reporting suite. Specifically I will look at how the ReportViewer in ASP.NET interacts with the server and include some design tips when using our reporting suite in your web applications.

    Starting int the newest reporting version, report documents are no longer created on postbacks, but instead created on a callback This allows each page to be generated on demand.

    For this reason reports should be assigned to a ReportViewer in the Page_Load event handler. After this, a report document is created every time the Web page is re-loaded.

    protected void Page_Load(object sender, EventArgs e) {
        ReportViewer1.Report = new XtraReport1();
    } 

    The only exception to this rule is when you use a ReportDocumentMap with ReportViewer, in which case a report document is created on a postback (to return its bookmark hierarchy to the client).

    In addition, please note that in order to avoid issues regarding the client-server interaction of ReportViewer, we recommend you assign any properties to it either in markup, or in code, but not using both these approaches simultaneously.

    Another feature I would like to highlight is of special importance if your Web application is intended to work with large amounts of data.

    In this case, you can create your report’s data source exclusively when a report document is being generated in the special XtraReport.DataSourceDemanded event handler. For example:

    private void report_DataSourceDemanded(object sender, System.EventArgs e) {
        var dataSet1 = new DataSet1();
        var newRow = dataSet1.DataTable1.NewRow();
        dataSet1.DataTable1.Rows.Add(new object[] { "Field1", "Field2" });
        XtraReport report = (XtraReport) sender;
        report.DataSource = dataSet1;
    }
    As always, if you have any questions and/or comments, please do let us know!
  • Creating and Displaying Reports using XPO

    Hello! I wanted to start a series describing our fabulous reporting suite by looking at it from three different angles:

    1. Data – where does the report information reside?
    2. Layout – how do we want to present the data within the report pages?
    3. Presentation – what client side technology will we be using for visualizing the reports?

    The distinction between #2 and #3 is subtle yet extremely important. Our reporting suite is agnostic when it comes to #1 and #2 but very specific when it comes to #3. Laying out the report elements on the report itself should be completed (or at least prototyped) before the report is shown in any of our supported environments (WinForms, ASP.NET MVC, ASP.NET WebForms, Silverlight, WPF, and LightSwitch).

    This particular installment will deal primarily with Data and Presentation. We will be looking at using an XPOCollection as the source of the data and then showing how to visualize the report in WinForms and ASP.NET.

    Data

    The first thing to do is create a class library project to house the XPO objects themselves.

    XPO Class Project

    This project has two classes that inherit from XPObject that have a many-to-many association between them. For more details on XPO we have a great Getting Started tutorial if you would like more information.

    XPO Person Object

    The class view above shows the type of data that I added to the Person XPO class. In addition the Category class has a Name and a Description. There is also a many-to-many between Persons and Categories.

    XPO Many-to-many Association

    Layout

    The next thing I did was to add a new class library project to house the actual reports. Once you add a report and add a reference to our XPO library we need to instruct the report to use XPO as its data source. The easiest way to do this is to add an XPCollection to the report’s design surface:

    Report XPCollection

    Once this is done you will have all of the available fields in order to begin laying out the report. We will not spend too much time here. The key is to get some fields on the design surface in order to make sure the whole process is indeed working.

    Presentation – WinForms

    Now its time to add a third project – the WinForms viewer project. Usually I add a button to the existing form and on its click event instantiate and show the report. I thought I would try to add a little more value by showing how to create a custom report viewer form. On the main form drag a PrintBarManager onto the form’s surface:

    Windows Print Bar Manager

    Once this is added you should see all of the elements available in our standard report viewer dialog. Lastly we need to hook up this new report viewer to our report:

    loadreport

    The key element here is to set the print control’s printing system to the reports printing system. This will ensure that both items are talking about the same things when generating the report. The result:

    Windows Report Viewer

    If XPO is left on its own here it will (by default) create an access database to house anything you might end up saving. Now on to ASP.NET!

    Presentation – ASP.NET

    In ASP.NET things are a bit different. In the WinForms project XPO did a lot of the heavy lifting that it simply cannot do in ASP.NET. In this case all we have to do is tell ASP.NET where the database resides. Once we create a new ASP.NET project and add references to the data and reports assembly we add the Access database to the App_Data folder and specify the following in the Application_Startup (in the Global.asax; see docs for more details):

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        string conn = AccessConnectionProvider.GetConnectionString(
            Server.MapPath("~\\App_Data\\data.mdb"));
        XPDictionary dict = new ReflectionDictionary();
    
        // Initialize the XPO dictionary. 
        dict.GetDataStoreSchema(typeof(Person).Assembly);
        IDataStore store = XpoDefault.GetConnectionProvider(conn,
            AutoCreateOption.DatabaseAndSchema);
        XpoDefault.DataLayer = new ThreadSafeDataLayer(dict, store);
    }

    On the Default.aspx page I switch to Design mode and drop a ReportToolbar and a ReportViewer on to the design surface. If we added the references properly we should be able to select the report right on the ReportViewer’s design surface:

    ReportViewer Smart Tag

    We do the same thing with the ReportToolbar except in this case we are selecting the target report viewer. That should be it!

    ASP.NET Report Viewer

    Summary

    Hope this was helpful! The main idea was that the data, the layout, and the presentation were all separate logical concepts (and in fact separate projects). If these concepts are kept separate there is nothing keeping you from swapping out data representations as well as client representations (i.e. now we want a Silverlight XPO report etc).

    As always, if there are any comments and/or questions, feel free to get a hold of me!

    Seth Juarez
    Email: sethj@devexpress.com
    Twitter: @SethJuarez

    Want The Best Reporting Tool Ever?

    Get The No-Compromise Reporting Tool for WinForms, ASP.NET, Silverlight and WPF! - Native integration with DevExpress WinForms and ASP.NET Controls, unequalled design-time productivity, industrial-grade features. Try a fully-functional version of DXperience for free now: http://www.devexpress.com/Downloads/NET/

    Let us know what you think of our Reporting Suite by rating it in the VS Gallery!

    Follow SethJuarez on Twitter

  • LightSwitch Reporting–A fully integrated data presentation solution (Charts)

    I wanted to continue to show off the amazing features that come bundled with our reporting offering for LightSwitch. Our developers have done a fantastic job incorporating *all* of the elements required to present data in a concise and effective manner. Today I thought I would show off the the embedded charts that come with our solution.

    Charts

    The old adage that “a picture is worth a thousand words” rings true when it comes to presenting information in charts. Charts graphically summarize vast amounts of data in a small amount of space while maximizing information comprehension. Our chart wizard is second to none when it comes to available chart options and customizations. There are over 50 distinct chart types with a myriad of ways to customize them. Some of the available customizations include interactivity, look and feel, indicators, constant lines (and we are only scratching the surface here people).

    Step 1: The data

    Enough chatter! Let’s take a look at how to do charts in LightSwitch reports. The first thing to remember is that our components work natively with LightSwitch Entities and Queries. We will start with where we left off after our LightSwitch Webinar. In this webinar we used the Course Manager sample application to create interactive reports. Lets continue by adding a calculated field to the Student Entity that calculates the number of enrolled courses per student:

    Student Entity

    Once the field is typed in we set the Type to integer, check the Is Computed field,

    Entity Property

    and select Edit Method to generate the proper value:

    Calculate Enrollment Counts

    These changes will then propagate to our custom LightSwitch Data Source control and enable us to create a bar chart depicting all students and the number the respective number of enrollments.

    Step 2: Adding the Chart

    There are really only three things that should be done in order to get the chart up an running within the report. Lets open the Student Report we created in the video. If you are starting from scratch create a new report and simply click on the report smart tag to select the Student entity as the report’s data source. Now lets drag a chart on to the report. Within LightSwitch all you have to do is Right-Click on the report and select Toolbox to be able to drag the control onto the design surface:

    Adding a Chart

    Once this action is complete, the Chart Wizard will automatically fire. The pages of most importance include the Chart Type page, the Series page and the Data page. In this example we will only have one series for the enrollment count. Once we select the chart type as a bar chart and rename the series we go over to the Data page and set the Argument binding

    Chart Argument Source

    and the Value bindings

    Chart Value Source

    Notice how the chart automatically understands the calculated field (EnrollmentCount) that we added previously. At this point you can click on Finish.

    Report Designer with Chart

    Step 3: Enjoy

    If you are following along with the completed project from the webinar, the screen should be prepared already. If not it is very easy to add a report screen to the LightSwitch application.

    Final Report with Chart

    Final Thoughts

    The best part of our reporting solution is that it is truly a fully integrated approach to presenting data in your LightSwitch application. Stay tuned! Next time we will look at additional reporting tools available in your analytics arsenal complements of DevExpress Reporting for LightSwitch!

    Take a look at our LightSwitch Page: http://www.devexpress.com/LightSwitch

    As always, if there are any comments and/or questions, feel free to get a hold of me!

    Seth Juarez
    Email: sethj@devexpress.com
    Twitter: @SethJuarez

    Want The Best Reporting Tool Ever?

    Get The No-Compromise Reporting Tool for WinForms, ASP.NET, Silverlight and WPF! - Native integration with DevExpress WinForms and ASP.NET Controls, unequalled design-time productivity, industrial-grade features. Try a fully-functional version of DXperience for free now: http://www.devexpress.com/Downloads/NET/

    Let us know what you think of our Reporting Suite by rating it in the VS Gallery!

    Follow SethJuarez on Twitter

LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2014 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners