ARTICLE

Getting Started with ReportViewer Control

Posted by Mahesh Chand Articles | ASP.NET using VB.NET September 06, 2007
I could not be happier when I saw the ReportViewer control as a part of Visual Studio 2005 controls. This article is an introduction to the ReportViewer control and how to write a simple report using the ReportViewer control in Visual Studio 2005.
 
Reader Level:

If you have written any reporting applications in .NET, you may be familiar with Crystal Reports and/or Microsoft SQL Server Reporting Services.

 

The ReportViewer control is a new addition to Visual Studio 2005, which is actually a Reporting Services component. This control has two versions - Windows Forms version and Web version. As you may presume, Windows Forms version is used to write reporting applications in Windows Forms applications and Web version is used to write ASP.NET Web applications.

 

Report Processing Modes:

 

The ReportViewer control supports two report processing modes:

 

  • Local processing modes
  • Remote processing modes

In Local processing mode, the ReportViewer control runs within the client application and the report processing is performed as a local process on the client machine where actual application is running.

 

In Remote processing mode, the ReportViewer control runs on a SQL Server 2005 Reporting Services report server. In this mode, the ReportViewer control is used to view the report that is already generated on the server. All processing from data retrieval to report rendering is performed on the report server. To use remote processing mode, you must have a licensed copy of SQL Server 2005 Reporting Services.

 

Both Windows and Web controls can be configured to run in local processing mode or remote processing mode.

 

Namespace and Assembly:

 

The ReportViewer control assemblies for Windows Forms and Web Forms versions are Microsoft.ReportViewer.WinForms and Microsoft.ReportViewer.WebForms respectively. You must have to import the namespace in your application before start using the ReportViewer control. If you use add the ReportViewer control by dragging and dropping from the Toolbox, the namespace and assembly references are added for you automatically.

 

Create a Simple Report:

 

Now let's create a simple report using the ReportViewer control. In this application, I will load data from a SQL Server database to generate reports.

  1. Create a Web Application using Visual Studio 2005.
  2. Drag and drop a ReportViewer control from Toolbox to the Web page.
  3. Right click on the Project in Solution Explorer and select Add New Item menu item and select DataSet from the list and keep DataSet1.xsd as name.
  4. The next screen is TableAdapter wizard, which asks you question about your database connection and SQL queries where you want data to be selected from. Just follow the wizard steps one by one and you will end up seeing DataSet in designer mode with your table name and columns. Close the designer. 
  5. Now right click on the Project again and select Add New Item and select Report from the available items and click Add button. See Figure 1.


Figure 1. 

  1. It will add Report.rdlc file to your project and will open the report designer, which looks like Figure 2. As you can see in the left side, you will see your DataSet.

 

Figure 2. 

  1. Now you can expand your DataSet and drag whatever column you want in the report to the report designer. I select three columns in Figure 3.


Figure 3.

  1. Now if you right click and select Properties on a TextBox, you will see Figure 4, where you can apply settings like visibility, navigation, format, font, and sorting. For now, you can say OK on this dialog. I will discuss these properties in more details in my following articles.

 

Figure 4. 

  1. Now go to the Web page and click the smart tag on ReportViewer and select Report.rdlc from the list. See Figure 5.


Figure 5. 

  1. That's it. Now if you run the application, you will see report. You can navigate through records, and export it to Excel or PDF using the Export option.

Summary:

The ReportViewer control available in Visual Studio 2005 makes reporting easier for .NET developers. This article was a basic introduction to ReportViewer control and how to get started with it. Now having Reporting Services component available in Visual Studio, you don't have to deal with Crystal Report, its distribution and licensing issues.

Login to add your contents and source code to this article
share this article :
post comment
 

Hi Mahesh, Thank you for posting such a nice article.Realy it helps. I have one issue. Could you please tell me what do to if i want a gridview layout of my report. Is there any option for this layout of report,If yes please tell me. I tried but didnt success to impliment gridview layout of my report. Waiting for your response. Vivek

Posted by Vivek Apr 14, 2011

hi,

I don't want to use wizard for configuring datasource to the Report Viewer. I want to this daynamically (at Runtime i-e through code)

For example

dataDridView1.DataSource = dataTable;

I want same for the Report Viewer.

Plz help me ..

Regards

Salman


Posted by Salman Khan Jun 27, 2010

I am using Visual Studio 2005 to develop an ASP.NET 3.5 web application. I followed your instructions but receive the following error when I run the page:

"A data source instance has not been supplied for the ata source 'DataSet3_Resident'"

So I added an SQLDataSource object to the page, specifying the same database table as the DataSet3.
Then, for the ReportViewer object Data Source (DataSet3), I specified the SQLDataSource as the instance.

Any idea why I am still getting this error?

Posted by Dan Bellerue Jun 17, 2010

Can you implement this article on windows based form.

Posted by silky garg Apr 29, 2010

I followed the steps but only the last record from the database is display.

Posted by Tuck Hoh Mar 30, 2010
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor