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.