A look at SAP Crystal Reports for Visual Studio 2010
page 4 of 6
by Vince Varallo
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 32718/ 63

Filtering Saved Data

Another nice new feature of Crystal Reports is the ability to dynamically filter the report without writing any code.  This is done with parameter fields and the new Saved Data option for the Selection Formula.  Assuming you followed the steps above you should close your browser to stop debugging.  Follow these steps to learn how to add this new feature to the Employee List report.

We'll change this report so the user can filter the report by an employee's hire date.

1.    Right click on the Parameter Fields node in the Field Explorer and select New… from the pop-up menu.

2.    Enter Hire Start Date for the Name.

3.    Change the Type to Date.

4.    Click the OK button.

5.    Right click on the Parameter Fields node again and select New… from the pop-up menu.

6.    Enter Hire End Date for the Name.

7.    Change the Type to Date.

8.    Click the OK button.

9.    From the main menu select Crystal ReportsàReportàSelection FormulaàSaved Data….

10. Enter the following formula:

if {Employee.HireDate} >={?Hire Start Date} and {Employee.HireDate} <= {?Hire End Date} then

11. Click the Save and close button.

12. Run the report again.  This time when it runs the user will be prompted to enter the Hire Start and End dates.

13. Enter 1/1/2000 for the Hire Start Date.

14. Enter 12/31/2000 for the Hire End Date.

15. Click the OK button.  You should only see records for employees hired in the year 2000.

16. On the left hand side of the viewer you should see a question mark inside parenthesis. (?).  Click on this.  This will display the parameters panel.

17. Change the start date to 1/1/2001 and the end date to 12/31/2001. 

18. Click the Apply button.  You should now see the employees hired in 2001.

This is a nice new way to display the parameters in a report rather than have the user refresh or run the report again.

View Entire Article

User Comments

Title: Need another sample   
Name: Matt Slay
Date: 2010-07-21 5:29:44 AM
Nice intro showing how it all from within CR, but I'd like to see a sample where I had data from a LINQ query (EF or Linq To Sql) or even DataTables, where the querying and filtering happens in code inside my DAL, and then how that data can be passed into the report.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-04-11 9:22:54 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search