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 #)