Asp.net report ReportViewer design (RDLC)

Source: Internet
Author: User

Asp.net report ReportViewer design (RDLC)

ReportViewer is a Microsoft report control. Its Design file is RDLC and its data architecture is dataset. As follows:

The serial number calls the built-in function. The name, income, and department are bound to the data source, and the Avatar is bound to the external image pointed to by the URL. The following is the implementation process.

1. Add a dataset

1. After creating a blank Web project, right-click the project and choose add> new item> DATA> select dataset. For details, see

2. Name the dataset datasetaskableable1

3. Double-click datasetaskableable1.xsd, right-click on the page, and add a data table.

4. Add columns in DataTable1 of the data table.

5. Set the Data Type of the Income column to Decimal.

Right-click the Income field and choose Properties> DataType.

Ii. Design RDLC

1. Create RDLC.

Right-click the project and choose add> new item> report.

Named Report1.rdlc

2. Add parameters.

Double-click Report. rdlc to add parameters.

3. Use Parameters

Drag a text box in the toolbox, select the text box, right-click, and choose text Properties> fx> set parameters. For details, see.

If you need to add a fixed text before the parameter, you need to use double quotation marks to enclose the text and connect it with &. If the text to be followed is a number, you need to use the Format function to convert it to a string.

3. Design Data Tables

(1) Add a dataset

(2) drag a "table" into the toolbox, drag the table from report data> dataset> select the corresponding field> into the table, and set the corresponding title.

(3). Sequence Number Column

(4). Avatar Column

Iii. aspx page

1. Create the default. aspx page

2. Add the ScriptManager and ReportViewer controls to the page.

3. Configure report Report1 for ReportViewer

4. Delete unnecessary code

5. backend code

 

Public partial class _ default: System. Web. UI. Page {protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {ReportViewer1.LocalReport. enableExternalImages = true; ReportViewer1.LocalReport. reportPath = Report1.rdlc; ReportViewer1.LocalReport. setParameters (new ReportParameter (ReportParameter1, Guid. newGuid (). toString (); DataTable dt = GetData (); ReportDataSource rds = new ReportDataSource (datasetemediatable1, dt); ReportViewer1.LocalReport. dataSources. clear (); ReportViewer1.LocalReport. dataSources. add (rds); ReportViewer1.LocalReport. refresh ();}}////// Simulate data //////
 Private DataTable GetData () {DataTable dt = new DataTable (dataname); dt. columns. add (new DataColumn (Name, typeof (string); dt. columns. add (new DataColumn (Income, typeof (decimal); dt. columns. add (new DataColumn (Dept, typeof (string); dt. columns. add (new DataColumn (Picture, typeof (string); DataRow row = dt. newRow (); row [Name] = James; row [Income] = 1000.00 m; row [Dept] = Personnel Department; row [Picture] = http://localhost:60000/demo_pictures/person1.jpg ; Dt. rows. add (row); row = dt. newRow (); row [Name] = Li Si; row [Income] = 1200.00 m; row [Dept] = Personnel Department; row [Picture] = http://localhost:60000/demo_pictures/person2.jpg ; Dt. rows. add (row); row = dt. newRow (); row [Name] = Wang Wu; row [Income] = 2000.00 m; row [Dept] = technical department; row [Picture] = http://localhost:60000/demo_pictures/person3.jpg ; Dt. Rows. Add (row); return dt ;}}
Localhost: 60000 is a server set up on your own IIS, and images are stored on the Internet.
 

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.