This tutorial walks you through creating an ASP.NET report based on the Northwind sample database. It shows how to add a client report definition file (RDLC), create a dataset for the RDLC, define queries using LINQ to Entities, design the report and add a ReportViewer web control to render the report in a ASP.NET web page. The report will have a chart control. The result can be filtered by two drop downs at the top..
At the end of the walkthrough, you should have a UI like the following. As shown, there is a product list report with an embedded chart. The chart shows the sum of Unit price for a given category. It is possible to filter the results by Category and Supplier. The drop downs auto post back when the selection is changed. This demo uses Visual Studio 2010 RTM.
This post is split into three parts. The last part has the sample code attached.
Creating an ASP.NET report using Visual Studio 2010 - Part 2
Creating an ASP.NET report using Visual Studio 2010 - Part 3
Lets start by creating a new ASP.NET empty web application called “NorthwindReports”
Creating the Data Access Layer (DAL)
Add a web form called index.aspx to the root directory. You do this by right clicking on the NorthwindReports web project and selecting “Add item..”
Create a folder called “DAL”. We will store all our data access methods and any data transfer objects in here.
Right click on the DAL folder and add a ADO.NET Entity data model called Northwind.
Select “Generate from database” and click Next.
Create a connection to your database containing the Northwind sample database and click Next.
From the table list, select Categories, Products and Suppliers and click next.
Our Entity data model gets created and looks like this:
Adding data transfer objects
Right click on the DAL folder and add a ProductViewModel. Add the following code. This class contains properties we need to render our report.
Add a SupplierViewModel class. This will be used to render the supplier DropDownlist.
Add a CategoryViewModel class.
Create an IProductRepository interface. This will contain the signatures of all the methods we need when accessing the entity model. This step is not needed but follows the repository pattern.
Create a ProductRepository class that implements the IProductReposity above. The methods available in this class are as follows:
- GetProducts – returns an IQueryable of all products.
- GetProductsProjected – returns an IQueryable of ProductViewModel. The method filters all the products based on SupplierId and CategoryId if any. It then projects the result into the ProductViewModel.
- GetSuppliers() – returns an IQueryable of all suppliers projected into a SupplierViewModel
- GetCategories() – returns an IQueryable of all categories projected into a CategoryViewModel
Your solution explorer should look like the following.
Build your project and make sure you don’t get any errors.
In the next part, we will see how to create the client report definition file using the Report Wizard.
- Adding a hyperlink in a client report definition file (RDLC)
- Rendering an RDLC directly to the Response stream in ASP.NET MVC
- ASP.NET MVC Paging/Sorting/Filtering using the MVCContrib Grid and Pager
- Localization in ASP.NET MVC 2 using ModelMetadata
- Setting up Visual Studio 2010 to step into Microsoft .NET Source Code
- Running ASP.NET Webforms and ASP.NET MVC side by side
- Pre-filtering and shaping OData feeds using WCF Data Services and the Entity Framework