Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create report in asp.net using Report Viewer

I am using Visual Studio 2010. I have worked on Crystal Reporting before that but now i want to generate reports using Report Viewer. As i am new to this topic please Guide me. Thanks !!!

like image 900
Sonam Mohite Avatar asked Apr 19 '12 06:04

Sonam Mohite


People also ask

What is Report Viewer in asp net?

The ASP.NET ReportViewer control is a composite of standard ASP.NET Web Server controls. The ASP.NET ReportViewer comes with four predefined skins: Default, WebBlue, Original and Office2007. The ASP.NET ReportViewer control's toolbar is immutable.

What is Rdlc Report in asp net?

The RDLC stands for Report Definition Language Client side. Actually It is an extension of report file created by using Microsoft reporting technology. The SQL Server 2005 version of Report Designer is used to create these files. The ReportViewer control in client side can directly execute the RDLC reports.


2 Answers

Basic tutorial for you

Adding and Configuring the ReportViewer Controls

Creating an ASP.NET report using Visual Studio 2010 - Part 1

Creating an ASP.NET report using Visual Studio 2010 - Part 2

Creating an ASP.NET report using Visual Studio 2010 - Part 3

How to use the Report Viewer Control to access a Reporting Services Server

like image 197
Pranay Rana Avatar answered Sep 17 '22 16:09

Pranay Rana


My code works to create Report for business class objects...

Creating Report using Business Class Objects & ReportViewer (ASP.NET/ C#) 1.Create Student Class

  public class StudentClass
  {
      public int No { get; set; }
      public string Name { get; set; }
      public string Degree { get; set; }
   }

2.Create Student Repository with GetStudents() function

public class StudentRepository : StudentClass
    {
        public List<StudentClass> studentList = new List<StudentClass>();

        public List<StudentClass> GetStudents()
        {            
            StudentClass student1 = new StudentClass();
            student1.No = 1;
            student1.Name = "Bhuvana";
            student1.Degree = "M.Tech";
            studentList.Add(student1);
            StudentClass student2 = new StudentClass();
            student2.No = 2;
            student2.Name = "Annie";
            student2.Degree = "B.Tech";
            studentList.Add(student2);
            StudentClass student3 = new StudentClass();
            student3.No = 3;
            student3.Name = "Muthu Abi";
            student3.Degree = "B.Tech";
            studentList.Add(student3);
            return studentList;
        }
    }

3.Using Report Wizard create “StudentReport.rdlc” and select DataSource

4.In Index.aspx add Script Manager and Report Viewer from ToolBox(Drag And Drop)

<div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>  
    <rsweb:ReportViewer ID="ReportViewer1" runat="server">
    </rsweb:ReportViewer>       
</div>

5.Modify Page_Load() method in code behind file

public partial class Index : System.Web.UI.Page
{
    StudentRepository sr = new StudentRepository();
    List<StudentClass> sc = new List<StudentClass>();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ReportViewer1.ProcessingMode = ProcessingMode.Local;
            ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report/Student.rdlc");
            sc = sr.GetStudents();
            IEnumerable<StudentClass> ie;
            ie = sc.AsQueryable();
            ReportDataSource datasource = new ReportDataSource("DataSet1", ie);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(datasource);
        }

    }
}

6.Build And Run

like image 25
Bhuvi Avatar answered Sep 19 '22 16:09

Bhuvi