Using DevExpress XtraReports with Iron Speed Designer


Learn how to apply Xtra Reports to Iron Speed Designer applications.
- Miles Gibson, Consultant and Principal of Milestone Consulting

March 16, 2009
Iron Speed Designer V6.X

Introduction

In this article, I will focus on integrating the XtraReports viewer into an Iron Speed application. XtraReports viewer is a reporting tool by DevXpress. The tool has a great web viewer control, with pagination, export-to-PDF, CSV, etc. It also provides a no-cost runtime license that you can distribute to clients with as many applications as you like.

In order to get a better understanding of how I work with XtraReports and Iron Speed Designer, you may want to read my article on using third-party controls with Iron Speed Designer first. You can retrieve my article here. You can also check out another article I wrote about integrating Iron Speed Designer and Data Dynamics Active Reports as well. That article is found at Active Reports and Iron Speed Designer.

Part I: Adding a Report Page in Iron Speed Designer

First, add a new blank Master page in your Iron Speed Designer application. Name it appropriately. Save and compile your application. For reference to this report page, call it "ShowReport.aspx".

Open your project with Visual Studio

There are two ways to open your Iron Speed Designer project with Visual Studio.

  • Open Visual Studio and select File-Open Web Site. Navigate to your Iron Speed Designer Project and select the folder where your application resides.

  • Launch Iron Speed Designer and open your application. Click the Visual Studio button as shown below:

Once Visual Studio has opened with your project:

  • Step one: Select the newly added report page, and call it "ShowReport.aspx".

  • Step two: Click on the Design tab, usually located near the bottom left of the page.

  • Step three: You should see a page that will display placeholder objects representing various parts of your Iron Speed Designer page. Ignore these.

  • Step four: From the toolbox, select the XtraReports toolbar control and drag it onto the page.

  • Step five: From the toolbox, select the XtraReports Report Viewer control and drag it onto the page, below the toolbar.


Note: If the DX:Web.v.7.3 ( or later ) tab is not visible, you will have to register the toolbox items in order to continue. Check the DevExpress installation shortcuts in your Start menu for a tool that will register these controls automatically.

You may want to rename the Report Toolbar from ‘ReportToolBar1’ and the Report View control from ‘ReportViewer1’ to something more meaningful.

Connect the Toolbar to the Report viewer using the available properties for the Report Toolbar. This is a good time to save.

Switch to Source view (tab at the bottom of this page). Look for code very similar to what is shown below:

Grab everything within the red bars, including the starting and ending td’s. Copy this to the clipboard.

Switch back to Iron Speed Designer and select the HTML view for this page. Locate this area, and highlight the section of code that relates to the Page Content, similar to above, but without the changes you just made to the ShowReport.aspx file in Visual Studio.

Paste the contents of your clipboard, overwriting the highlighted code. Remember you are copying HTML code from the HTML in Visual Studio to the HTML in your Iron Speed page. Don’t get it backwards or you will have to start over again ( See Getting Started!).

Save the change in Iron Speed Designer. This is an important step as you don’t want to lose your work when you recompile your application in Iron Speed Designer.

Okay, there is one more step and you can get down to the real deal. You have to tell Iron Speed Designer more about your XtraReport objects.

Switch back to Visual Studio and move to the top of the Source page. You will see a Register directive, like the one shown below, but for your version of XtraReports:

Highlight the entire register directive, starting and ending with the code highlighted in yellow. Copy this to the clipboard.

Switch to Iron Speed Designer and move to the top of the HTML page. Paste this code into a new line at the top of the page.

This is a good time to save.

Switch back to Visual Studio. Now select your project, found in the Solution Explorer pane. Right-click Add New Item. Select the XtraReport Class v7.x as shown below:

Let Visual Studio churn away until it has successfully added the XtraReport class file, which is really the code for your new report. Be patient as it could take a minute or more depending on the speed of your machine.

Part II: Using Parameters with XtraReports

Step one: Add Dataset via Add New Item, etc....

Wait a short while Visual Studio does things in the background.

Step two: Configure TableAdapter in Dataset

Double-click on the dataset to make changes

Then you will see:

Click the table adapter to configure. Look at the properties for this table adapter (you may have to right-click to do so).

Click the ellipsis to add or change parameters for this table adapter.

Click add to add a new parameter, or select the parameter to work with. Make sure you remember to select the Source column to associate this parameter with. Click Okay.

Note: The where clause of the WorkOrderTableAdapter must be modified the first time with the @WorkOrder variable.

Example:

Select * From WorkOrder Where WorkOrderId = @WorkOrder

You cannot do this until you have already entered the parameter for this table adapter.

If Visual Studio prompts you that it wants to regenerate commands, always say yes. If it does not provide this prompt, you need to right-click the Configure menu option and complete the steps therein.

Preview the data and provide a parameter value to prove that the parameter is correctly in place. If you supply a parameter value and clicking Preview still returns all rows, then something is wrong or missing. You need to go back to previous steps and try again.

Now you need to test your parameter to make sure that it works.

Step three: Preview data for TableAdapter by right-click Preview Data

Right click on the TableAdapter and select ‘Preview Data’.

Enter a value for the parameter. You should see filtered data appear:

Success! Now you need to add a new XtraReport to your project.

Step four: Add a new XtraReport via Add New Item = XtraReports 7.2 Class. Wait a minute while XtraReports does stuff behind the scenes

Step five: Click the top left corner of the report to change the report source. The image below shows the location with a red arrow.

Drag fields from either the ToolBox...

...or from the Field List that should now appear and/or be available to you:

The advantage of selecting fields from the Field List is that XtraReports will automatically bind them for you. If you need to create your own bound field, drag an xrLabel field over onto the design surface.

Select the xrLabel control. Look at the properties for this control to bind it to a field in your dataset table:

Once all of your fields are bound, you are ready to move on to the next step!

After you have added the ReportToolBar and ReportViewer Objects, then you can add the following code. Note that in the example below, I am passing in a parameter off of the URL, but you could also use Session variables, etc.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
    Dim rep As New WorkOrderReport(Me.Page.Request.QueryString("WorkOrder"))
    Me.ReportViewer.Report = rep
End Sub

Now you just need to let the report know about the parameter you are passing in to your WorkOrder Report. To do this, add a constructor method to your XtraReports report class. Open Visual Studio and load your web application. Open the App_Code are in Solution Explorer, and find the <ReportName>.vb or <Reportname>.cs file. Double click to open.

Insert the following code.

Public Sub New(ByVal WorkOrderId As Integer)
        MyBase.New()
        'This call is required by the Designer.
        InitializeComponent()
 
        Try
                Dim a As New dsWorkOrderTableAdapters.WorkOrderTableAdapter
                Dim b As New
                dsWorkOrderTableAdapters.vwWorkOrderMaterialsListDetailsTableAdapter
 
                Try
                        a.Fill(Me.dsWorkOrder1.WorkOrder, WorkOrderId)
 
                        b.Fill(Me.dsWorkOrder1.vwWorkOrderMaterialsListDetails, WorkOrderId)
 
                Catch ex1 As Exception
 
                End Try
 
    End Sub

Build and Run!

Conclusion

Incorporating XtraReports viewer with Iron Speed Designer will make your Iron Speed Designer applications even more appealing to your clients. By adding this powerful reporting tool to your arsenal, you can create paginated reports and export files easily in a variety of ways.

About the Author

Miles Gibson
Consultant and Principal of Milestone Consulting

Miles is a senior consultant and principal of Milestone Consulting and has been providing his clients with the right solutions for over twenty three years. He was the first person to offer formal Iron Speed Designer training, and has been coaching and mentoring Iron Speed users for over three years. Miles is an Iron Speed MVP who loves to help clients finish their projects. He is an experienced data modeler who believes in strong database architecture.

Contact the author.



  Privacy Statement