How C # uses ReportViewer to generate sample code sharing for reports

Source: Internet
Author: User
This article is mainly for you to introduce in detail the C # use ReportViewer generated reports related code, with a certain reference value, interested in small partners can refer to

This article is mainly using Microsoft's own control ReportViewer for the report design of small examples, the specific content as follows

Knowledge points involved:

ReportViewer: Located in the Microsoft.Reporting.WinForms namespace, used primarily for report display
Report: Reports, files ending in rdlc, visual design report templates.
Report data: Built-in fields, parameters, images, datasets (this report mainly uses parameters, and datasets)
ReportParameter: Instantiating a new report parameter with a name and value
ReportDataSource: The data source of a report is associated with a DataTable object

As follows:

The relevant code is as follows:


<summary>///Setup Report///</summary> private void Setreport () {//First step: Clear previous data This.rptView.LocalRepor   T.datasources.clear ();   Step Two: Specify the report path This.rptView.LocalReport.ReportPath = "REPORT2.RDLC";   Step three: Construct a new datatable datatable dt = new DataTable ("DataTable1"); Dt.   Columns.Add ("Name"); Dt.   Columns.Add ("Score"); Dt.   Columns.Add ("Id"); Dt.   Rows.Add (new object[] {"Language", "Y0001"}); Dt.   Rows.Add (new object[] {"Math", "S0001"}); Dt.   Rows.Add (new object[] {"English", "E0001"});   The name cannot be written incorrectly, and the dataset name in the report is consistent reportdatasource Rdsitem = new ReportDataSource ("DataSet1", DT);   There can be more than one data source This.rptView.LocalReport.DataSources.Add (Rdsitem); Fourth step: Construction parameters list<reportparameter> Lstparameter = new list<reportparameter> () {New ReportParameter ("Title") , This.txtTitle.Text), New ReportParameter ("Id", This.txtId.Text), New ReportParameter ("Name", This.txtName.Text), n EW ReportParameter ("Age", This.txtAge.Text), New ReportParameter ("Sex", This.txtSex.text), New ReportParameter ("Salary", This.txtSalary.Text), New ReportParameter ("Depart", This.txtDepart.Text)};   This.rptView.LocalReport.SetParameters (Lstparameter);   This.rptView.ZoomMode = zoommode.percent;   this.rptView.ZoomPercent = 100;  Fifth step: Refresh the report This.rptView.RefreshReport (); }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.