• How to create report using ReportViewer in ASP.NET

    by  • May 6, 2014 • Microsoft .NET C# (C-Sharp), Microsoft ASP.NET • 0 Comments

    There are few tools and APIs used to generate and display reports in ASP.NET. Crystal Report is one of them and it is a good reporting tool. Hopefully, I will write few articles on Crystal Reports. Today, I will show you the use of ReportViewer control in ASP.NET.

    ASP.NET has provided a server control in Visual Studio for reporting that is called ReportViewer. ReportViewer control is provided so that you can process and display reports in your applications. It is a freely redistributable control that enables embedding reports in applications developed is ASP.NET. Reports can be designed with drag-and-drop simplicity using report designer included in Visual Studio 2010.

    You can process your data efficiently using ReportViewer and it can perform sorting, filtering, aggregation and grouping using ReportViewer reporting engine. ReportViewer supports a variety of ways to display data such as list, table and chart. You can also create reports which are visually good by setting fonts, colors, border styles, background images. ReportViewer also supports multiple other things like conditional formatting, collapsible sections, interactive sorting and document maps. You can also export your reports into Word, Excel and PDF formats.

    ReportViewer control can work in two modes. It can process and render reports using built-in engine in local mode or it can work in server mode. ReportViewer control displays one report at a time but you can combine multiple ReportViewer controls to display multiple reports simultaneously. You can use smart tags to configure ReportViewer control and you can also write code if you want to configure it programmatically.

    Now let’s see how to create a report using ReportViewer control.

    • Create a web application in visual studio 2010 and add a webform into it.
    • Add a report file from reporting tab in add new item window.
    • Create a XML schema file. I have used following code and run the project to create it.

    • Add this XML schema file to your web application as an existing file.
    • Open Report1.rdlc file and click on new > Dataset from Report Data tab on left to add new DataSet

    Add Dataset

    • Select Dataset and click ok

    select dataset

    • Now insert textbox in Report1.rdlc file and drag and drop columns from Report Data tab

    drag and drop

    • Add reference of Microsoft.ReportViewer.Webforms in your application
    • Add a ScriptManager and a ReportViewer control in your webform

    • Add following namespaces in code file

    • Now add following method to generate report

    • Add following code in page load event to get data for one ID

    • If you want to convert your report in PDF format and save it to specific location, you can write following lines of code at the end of GenerateReport() method

    • Now you can see report in your browser and you can also download complete code sample from below link

    Best WordPress Themes and Plugins with Great Team and Support!

    Avatar of GetCodeSnippet.com


    GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.

    Leave a Reply