Binding Data to the ReportViewer Control Dynamically in ASP.NET 2.0
(Page 1 of 6 )
This is the second article in a series focusing on designing and presenting native reports using ASP.NET 2.0. Throughout this series, I will focus on working with the “ReportViewer” control in local mode to develop web-based applications.
A
downloadable zip file is available for this article.
If you are new to working with the ReportViewer control, I strongly suggest you go through my first article in this series. That article really gives you a step-by-step approach to working with the ReportViewer control.
The entire source code for this article is available in the form of a downloadable zip file. The solution was developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Server 2003 Enterprise Edition together with Microsoft SQL Server 2005 Developer Edition. I didn’t really test the solution with any other or previous editions.
Binding a SELECT statement to a ReportViewer control in ASP.NET 2.0: design
I discussed several types of reporting strategies to implement in ASP.NET 2.0 applications in my first article. I also gave a step-by-step approach to working with the ReportViewer control in the same article. So I will not be repeating any of that material here.
In my previous article, I developed reports by directly connecting to database tables/views. That scenario won't be helpful every time. Let us imagine that I would like to develop a report based on a dynamic SELECT statement. This is a little bit tricky when compared to the approach I discussed in my previous article.
First of all, we need to keep in mind that any “table” in a report (at local mode) must adhere to a structure. This structure will generally be a “strongly-typed-dataset.” Without creating a strongly-typed-dataset, it is very difficult to design a report. Creating a strongly-typed-dataset was covered in my previous article.
Even now, to bind a report to a SELECT statement, we need to create a strongly-typed-dataset which contains exactly the same columns we retrieve using the SELECT statement. In other words, we will make filters, joins, sorting etc. dynamic, but not the structure (or set of columns). The structure (or set of columns) must always remain the same when designing or developing reports.
For this scenario, I created a strongly-typed-dataset (called SalesData.xsd) as follows.

It is simply a data table (dragged from the toolbox) with user specific columns. It has no relation to any database, and no tableadapters are created.
I added a new report (called SampleReport.rdlc) to the project and attached it to the dataset as follows:

Next: Binding a SELECT statement to a ReportViewer control in ASP.NET 2.0: code >>
More ASP.NET Articles
More By Jagadish Chaterjee