Usage of. NET reports

Source: Internet
Author: User

Data sources can be divided into two types. One is to use a strong data source, which can be easily implemented through the data source Configuration Wizard. Another type is to use business objects. For business objects, they are actually some classes that support ienumerable, such as generic sets. If a class defines a public method and the return type of the method is the type that implements the ienumerable interface, visual studio automatically recognizes this class, you can use the namespace where the class is located as the data source, and the Set returned by the common methods of the class as the available dataset.

The report design mainly targets the. rdlc file. On its design interface, we can drag a variety of report controls to display reports. Set the dataset of The. rdlc file and the page layout. The report Presentation Function displays the Report on the Application page, allowing you to conveniently view and operate the report. The report display is mainly implemented by dragging a reportviewer control on the asp tutorial x page. For the reportviewer control, you need to set the report to be presented and set its data source. The following describes how to use a generic set as a report data source. 1. Add a public class and a method to return a generic set. View code
namespace reportdemo
{
public class person
{
public string username { get; set; }
public string password { get; set; }
public int age { get; set; }
}
public class test
{
public static list<person> getperson()
{
list<person> list = new list<person>()
{
new person{username="zhang san",password="123",age=10},
new person{username="li si",password="qwe",age=20}
};
return list;
}
}
}
2. Add a report file. 3. Set the report dataset, click the report data tab, and click Create dataset. In the displayed window, select the data source and available dataset. We can see that vs has automatically bound the public class we added for us. 4. Select the Toolbox tab to view many report items, including text boxes, line charts, tables, matrices, rectangles, subreports, charts, etc. Drag and Drop a table to the report. Switch to the report data tab and drag the fields to the table to set the columns to be displayed. 5. Right-click the header and select the attributes of the text box. In the displayed window, you can set attributes such as alignment, Font, fill, and interactive sorting to set the style of the header. 6. After setting, the basic settings of the report file are complete. Next, you need to set the report to be presented by the reportviewer control and its data source. Click the small arrow on the right of the reportviewer control and select the report you just created. 7. Set the report data source by setting the data source of the reportviewer control in the background code. If you want to display report data when loading the page, you must add if (! Page. ispostback) attribute, otherwise it will be reloaded continuously.
protected void page_load(object sender, eventargs e)
{
if (!page.ispostback)
{
reportdatasource bb = new reportdatasource("dataset1", test.getperson());
reportviewer2.localreport.datasources.clear();
reportviewer2.localreport.datasources.add(bb);
}
}
8. Now, the report function is basically implemented, and the page running effect is as follows.

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.