. Net MVC report Creation

Source: Internet
Author: User

1. Create a New webform page and drag scriptmanager and reportviewer to the page.

2. Add a folder under the website, for example (reports folder)

3. In the reports folder, select new item and add a "dataset "... The suffix is XSD (example. Order. XSD)

4. Drag and Drop two able controls in order. XSD, which is equivalent to the database table. If you want to write the desired data field, the field name must be the same as the name of the database table column.
The datatable name is recommended to be the same as the database table name (for example, order orderdetail). You also need to modify the Data Type of the added field and select

5. add new items in the Reports folder and select report (report1.rdlc)

7. Drag and Drop controls in the toolbox of report1.rdlc. Tables and text boxes are generally used.

8. After configuring the dataset, write the code in the webform form load.
Using Microsoft. Reporting. webforms;

If (! Ispostback ){
Reportviewer1.localreport. reportpath = server. mappath ("~ /. Rdlc path ");
Reportdatasource DS = new reportdatasource ();
DS. Name = ""; // dataset name
DS. value = ""; // It can be a set or an object.
Reportviewer1.localreport. CES. Add (DS );
Reportviewer1.localreport. Refresh ();
}

9. The eighth method is webform. If MVC is used as a report, the eighth method should be changed to this method.
Write an action in the controller.
Public actionresult report (int id ){
Localreport = new localreport (); // a new report object
Localreport. reportpath = server. mappath ("~ /Content/reports/orderreport. rdlc "); // always report
Order order = orderbiz. fetchbykey (ID );
Reportdatasource rds1 = new reportdatasource ("order", new list <order> {order });
Localreport. CES. Add (rds1 );
Reportdatasource rds2 = new reportdatasource ("orderdetail", order. Details );
Localreport. CES. Add (rds2 );
// The following figure shows the default system settings for direct replication.
String reporttype = "pdf ";
String mimetype;
String encoding;
String filenameextension;

// The deviceinfo settings shocould be changed based on the reporttype
// Http://msdn2.microsoft.com/en-us/library/ms155397.aspx
String deviceinfo =
"<Deviceinfo>" +
"<Outputformat> pdf </outputformat>" +
"<Pagewidth> 8.5in </pagewidth>" +
"<Pageheight> 11in </pageheight>" +
"<Margintop> 0.5in </margintop>" +
"<Marginleft> 1In </marginleft>" +
"<Marginright> 1In </marginright>" +
"<Marginbottom> 0.5in </marginbottom>" +
"</Deviceinfo> ";

Warning [] warnings;
String [] streams;
Byte [] renderedbytes;

// Render the report
Renderedbytes = localreport. Render (
Reporttype,
Deviceinfo,
Out mimetype,
Out encoding,
Out filenameextension,
Out streams,
Out warnings );
// Response. addheader ("content-disposition", "attachment; filename = northwindcustomers." + filenameextension );
Return file (renderedbytes, mimetype );
}

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.