Making a report using the ReportViewer Control in ASP. NET (C #)

Source: Internet
Author: User

Environment: VS2010

1. Create a new Default.aspx file and drag the ReportViewer1 control and ScriptManager1 onto the page.

(1), select Design New report from the ReportViewer1 control's taskbar, and the Report Wizard dialog box appears.

Set the following in turn:

DataSet properties, select or set the DataSet.

Arrange fields, drag and drop the corresponding fields into the box for the row Group, column group, Value field.

Select Layout, and select the appropriate layout as needed.

Select style, select the style you prefer, and complete the Report Wizard.

(2), select the ReportViewer1 control Selection report as REPORT1.RDLC

(3), adjust the report layout or redesign the report as needed.

2, in the Default.aspx.cs page, add code to display the report.

protected void Button1_Click (object sender, EventArgs e)

{

Connecting to a database

SqlConnection myconn = new SqlConnection ();

MyConn. ConnectionString = strconn;

Execute Query

String selstr = "Select Dwmc,gwmc,zprs from GWB";

SqlDataAdapter da = new SqlDataAdapter (Selstr, myconn);

DataSet ds = new DataSet ();

Da. Fill (DS);

Set up a data source

ReportDataSource rds = new ReportDataSource ("DataSet1", ds. Tables[0]);

Reportviewer1.visible = true;

ReportViewer1.LocalReport.DataSources.Clear ();

REPORTVIEWER1.LOCALREPORT.DATASOURCES.ADD (RDS);

ReportViewer1.LocalReport.Refresh ();

}?

Attention:?

(1), to import the following namespaces:??

Using System.Data;

Using System.Data.SqlClient;

Using System.Configuration;

Using Microsoft.Reporting.WebForms;?

(2). Define Connection string variables

public string strconn = configurationmanager.connectionstrings["ApplicationServices"]. ConnectionString;??

(3), the dataset name of the report data source in the code (the Scarlet Letter section above) must match the name of the dataset dataset used in the report template.

3. The result of operation is as follows:?

Making a report using the ReportViewer Control in ASP. NET (C #)

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.