In this tutorial,  I create a project in ASP.net Web Application and make report using Report Viewer control and RDLC file.  This Project user can Print, export PDF, WORD, EXCEL file using Report viewer control. This article will explain how to use Report Viewer in ASP.NET Web application.

I. What is Microsoft Report Viewer?

  • Microsoft Report Viewer is a powerful .NET control allowing the use of RDL and RDLC reports in WinForms and ASP.NET applications. It enables users to view and export reports to different formats. The control is included with Microsoft Visual Studio 2010, 2012, and 2015, and is available as a free download from Microsoft. However, Visual Studio 2017 (and higher) does not have RDLC Reporting Tools installed by default. It can be installed as described at application integration integrating reporting services using report viewer controls get started

II. What is ASP.NET?

  • ASP.NET is an open source web framework, created by Microsoft, for building modern web apps and services with .NET. ASP.NET is cross platform and runs on Windows, Linux, macOS, and Docker.

Please click HERE about SQL Server..

III. Requirements

Before we start, Please make sure to have installed the following

  • The latest version of Visual Studio
  • SQL Server

Let’s Start;

IV. Create ASP.NET Web Application

  • Select File > New > Project.
  • Select ASP.NET Web Application (.Net Framework). Click Next.
  • Configure your new application
    • Project Name “Input your application name”;
    • Location “Location/directory of your application “;
    • Framework “Select the latest one”;
    • Click “
  • Configure your new application
    • Project Name “Input your application name”;
    • Location “Location/directory of your application “;
    • Framework “Select the latest one”;
    • Click “Create Button”;
  • Select the MVC during create web application
    • uncheck the HTTPS // Advanced -> Configure for HTTPS;
    • lastly click “Create Button”

V. Install ReportViewerForMVC in NuGet packages

What is NuGet Packages

  • NuGet is a package manager that delivers compiled source code (DLLs) and other files (scripts and images) related to code. A NuGet package takes the form of a zip file with the extension . nupkg. This makes adding, updating, and removing libraries easy in Visual Studio applications.
  • Follow this two option to go to NuGet’s manager.
    1. Tools -> NuGet Packages Manager -> Manage NuGet packages for Solutions;l
    2. Right Click Project -> Manage Nuget Packages
  • Here. Select Browse option, Search “ReportviewerforMVC” and Select the ReportViewerForMvc14 then Install.
  • Click Accept if this is Prompt.
  • after installing. Microsoft Report Viewer packages shown in Project Reference.
  • also there is a .aspx file generated after ReportViewerForMVC installed.
  • Instead of creating manually, the ReportViewerForMVC will set and create that file for you.

Let’s proceed.

VI. Create Dataset in ASP.NET

  • What is data set?
    • data set is a collection of data. In other words, a data set corresponds to the contents of a single database table, or a single statistical data matrix, where every column of the table represents a particular variable, and each row corresponds to a given member of the data set in question.
  • Follow this steps for creating DataSet
    1. Create a Folder name “Reports“. For creating folder. Right Click the Project and add new folder.
    2. Right Click the Report Folder, Click add and New Item.
    3. Click Data Option is Left side, DataSet and name “Report.xsd” and Click Add button.
    4. Now you can see the dataset file in Reports folder.
  • Add DataTable in DataSet File.
    1. Right Click the Board of Dataset -> click Add -> DataTable
  • add this following columns in DataTables

VII. Create Report .RDLC file in ASP.Net

  • if report not available in your VS, Just Click Here to install Report Viewer.
    • to install report viewer, you need to close your VS. and reopen after done installed.
    • Search Report -> select Report and name “Report1.rdlc” and Click Add.

VIII. Connect DataSet to Report1.RDLC file

  • Right Click the Datasets Folder and Click Add Dataset
  • Fill out the Name field, choose Reports name of out DataSet, refer this link. Select the name of DataTable from DataSet. In my case the name of DataSet file is Dataset1 and the name of DataTable is DataTable1. then Click Ok.
  • Now you see the column of datatable here in DataSet folder.,

IX. Add Table in RDLC report viewer.

  • Right Click the rdlc report and click Insert , select Table.
  • And add the field like this.

X. Add Report Method in HomeController.

  • Home Controller
  • Report Method in Home Controller
 public ActionResult Report()
        {

            DataTable dt = getData();

            ReportViewer view = new ReportViewer();
            ReportDataSource dtsource = new ReportDataSource("DataSet1", dt);
            view.LocalReport.DataSources.Clear();
            view.LocalReport.DataSources.Add(dtsource);
            view.LocalReport.ReportPath = @"Reports\Report1.rdlc";

            view.Width = 1000;

            view.LocalReport.Refresh();

            ViewBag.ReportViewer = view;
            return View();
        }
  • Internal Class getData(), generate sample user data.
/// <summary>
        /// Internal Class generate sample users
        /// </summary>
        /// <returns></returns>
        public DataTable getData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("id");
            dt.Columns.Add("username");
            dt.Columns.Add("name");
            dt.Columns.Add("email");
            dt.Columns.Add("status");
            dt.Columns.Add("tdt");


            for (int i = 1; i <= 10; i++)
            {
                dt.Rows.Add(i.ToString(),
                            "user" + i.ToString(),
                            "User " + i.ToString(),
                            "user" + i.ToString() + "@user.com",
                            "action" + i.ToString(),
                            DateTime.Now.ToString()
                    ) ;
            }
            return dt;
        }
  • Report View .cshtml
@using ReportViewerForMvc

@if(ViewBag.ReportViewer != null)
{
    @Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, new { @Width = 1000, @Height = 700 });
}
else
{
    <center><h1>Error in Error</h1></center>
}
  • Home Controller
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebDemo_ASP.NET_RDLCReportView.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult Report()
        {

            DataTable dt = getData();

            ReportViewer view = new ReportViewer();
            ReportDataSource dtsource = new ReportDataSource("DataSet1", dt);
            view.LocalReport.DataSources.Clear();
            view.LocalReport.DataSources.Add(dtsource);
            view.LocalReport.ReportPath = @"Reports\Report1.rdlc";

            view.Width = 1000;

            view.LocalReport.Refresh();

            ViewBag.ReportViewer = view;
            return View();
        }


        /// <summary>
        /// Internal Class generate sample users
        /// </summary>
        /// <returns></returns>
        public DataTable getData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("id");
            dt.Columns.Add("username");
            dt.Columns.Add("name");
            dt.Columns.Add("email");
            dt.Columns.Add("status");
            dt.Columns.Add("tdt");


            for (int i = 1; i <= 10; i++)
            {
                dt.Rows.Add(i.ToString(),
                            "user" + i.ToString(),
                            "User " + i.ToString(),
                            "user" + i.ToString() + "@user.com",
                            "action" + i.ToString(),
                            DateTime.Now.ToString()
                    ) ;
            }
            return dt;
        }
    }
}

OutPut

Happy Coding…

  • Thank you for visiting my web portfolio. Please subscribe via email to notify every time we have new posted blog. Thank you.

GitHub Repository

Support and follow my GitHub profile, to get the source code of this project. click GitHub Here!.

Related Topics

3 Replies to “Use Report Viewer in ASP.NET Web Application (.NET Framework) Using C#”

  1. Awesome website you have here but I was curious if you knew of any message boards that cover the same topics talked about here? I’d really like to be a part of online community where I can get responses from other knowledgeable people that share the same interest. If you have any recommendations, please let me know. Appreciate it!

  2. Good day! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us beneficial information to work on. You have done a wonderful job!

  3. Thanks for your posting. One other thing is when you are advertising your property on your own, one of the problems you need to be aware about upfront is how to deal with property inspection reviews. As a FSBO owner, the key towards successfully switching your property as well as saving money about real estate agent profits is understanding. The more you understand, the softer your home sales effort might be. One area exactly where this is particularly essential is reports.

Leave a Reply

Your email address will not be published. Required fields are marked *