Rdlc report Quick Guide

Source: Internet
Author: User

Rdlc reports are Microsoft's own reports and have been integrated into vs2010. They are more lightweight than Crystal Reports. More importantly, they can be used directly in web projects.

Procedure:

1. Create a dataset

Right-click-> Add new item-> dataset (named ds_emp in this example). The following interface is displayed:

Right-click-> Add-> datatable, add a table, name it t_emp, and add two columns, empno, and empname, all of which are in the string type. The following figure shows the result:

NOTE: If BizTalk is installed on the machine, after dataset is enabled, it may be as follows:

In my opinion, this editing method is inconvenient. You can right-click "--> open with" on ds_emp.xsd and set the dataset editor to the default editor on the pop-up page.

 

Ii. Create an rdlc report

Right-click the project and choose add new item> report. Add the report and name it report_emp.rdlc. The Report Editing page is displayed. Drag a table from the toolbox to the blank report area.

A dataset selection interface is displayed:

Select ds_emp and click "OK". A grid is displayed in the report layout.

Note: in most cases, in the data source drop-down box, not identifies a dataset in the current project. In this case, you need to right-click the solution rdlc file --> open with --> XML (text) Editor and directly edit the rdlc file (the report rdlc file is actually an XML file ), insert the following content before the node

<Datasources> <datasource name = "ds_emp"> <connectionproperties> <dataprovider> system. data. dataset </dataprovider> <connectstring>/* local connection */</connectstring> </connectionproperties> <RD: ceceid> d01eef15-1518-4df0-a45a-a17d24570e3a </RD: performanceid> </datasource> </datasources> <datasets> <dataset name = "t_emp"> <fields> <field name = "empno"> <datafield> empno </datafield> <RD: typename> system. string </RD: typename> </field> <field name = "empname"> <datafield> empname </datafield> <RD: typename> system. string </RD: typename> </field> </fields> <query> <datasourcename> ds_emp </datasourcename> <commandtext>/* local query */</commandtext> </query> <Rd: datasetinfo> <RD: datasetname> ds_emp </RD: datasetname> <RD: schemapath> app_code \ ds_emp.xsd </RD: schemapath> <RD: tablename> t_emp </RD: tablename> <RD: tableadapterfillmethod/> <RD: tableadaptergetdatamethod/> <RD: tableadaptername/> </RD: datasetinfo> </dataset> </datasets>

Note: <RD: schemapath> App_code \ ds_emp.xsd </RD: schemapath> It is best to set schemepath in this node to a relative path. Otherwise, if other people are inconsistent with the physical path of your local machine during development by multiple teams, after the dataset definition changes (for example, a new field is added ), in the report data panel of the report design, you cannot right-click-> refresh to refresh the dataset.

Then double-click the rdlc report in the normal way to view a dataset in the report data panel on the left.

Move the cursor to the cell. Note that there is a small icon (for example) in the upper right corner. Click this icon to list fields in the dataset.

Add columns to be printed in sequence

A little bit more modification, even if a simple report design is completed

 

3. Embed reports into webpages

Create An ASPX page, drag and drop a reportviewer to the page, and then drag and drop a scriptmanager to the page, the final Code is as follows:

 <% @ page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. CS "inherits =" _ default "%> <% @ register Assembly =" Microsoft. reportviewer. webforms, version = 10.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a "namespace =" Microsoft. reporting. webforms "tagprefix =" rsweb "%> 
         
   
   
  

some changes also occur in Web. config:

<? XML version = "1.0"?> <! -- For more information on how to configure your ASP. NET application, please visithttp: // go.microsoft.com/fwlink /? Linkid = 169433 --> <configuration> <system. web> 

It mainly includes some additional content under the System. Web/httphandlers and assemblies nodes.

Finally, use the code to get data in default. aspx. CS.

 
Using system; using system. data; using Microsoft. reporting. webforms; public partial class _ default: system. web. UI. page {protected void page_load (Object sender, eventargs e) {If (! Ispostback) {filldatatoreport () ;}} void filldatatoreport () {// create some sample data datatable dt = new datatable (); DT. columns. add ("empno", typeof (string); DT. columns. add ("empname", typeof (string); DT. rows. add ("000", "Yang Guo under the bodhi tree"); DT. rows. add ("001", "Zhang San"); DT. rows. add ("002", "Li Si"); DT. rows. add ("003", "Wang Wu"); // specify the report to be loaded and fill in the data. This. reportviewer1.localreport. reportpath = "report_emp.rdlc"; this. reportviewer1.localreport. datasources. add (New reportdatasource ("t_emp", DT ));}}

You can view the online reports on the page:

 

 

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.