Telerik Reporting Telerik Reporting Q1 2012 |
Creating a Simple Report |
Send Feedback |
Create the Class Library for the Reports
To create even simple reports you start by creating a class library to contain your report and a web, windows or Silverlight application to display the report.
Caution |
---|
It is possible to put the report definition and viewer in the same application but this route is not recommended. See this topic on best practices for more information. |
- Select File | New | Project from the Visual Studio File menu. Select the Class Library project, give it a name and location. Click the OK button to close the dialog.
- Right-click the project context menu and select Add | New Item | Telerik Report. Enter a name for the report class and click the Add button to close the dialog. In this example we name the report class file "ProductList.cs".
- The Telerik Report Wizard will appear automatically to help you select data and design your report quickly. Once you have the basic report layout you can go back to edit the report, add data columns and tweak the format. Click the Next button.
- On the Report Choice Page of the Report Wizard, select New Report and click the Next button.
- On the Choose Data Source page of the Report Wizard, select Add New Data Source.
- The DataSource Wizard is started. Select the SqlDataSource component icon and click the OK button.
- On the Choose Your Data Connection page select a connection for the AdventureWorks database from the drop down list. If you do not have it in the dropdown list, click New Connection and create a connection to it. When done click the Next button.
- The Save the Connection String step appears, where you can save the connection string in the application configuration file if you want with the name you want. Click Next.
- The Configure Data Source Command step will display next.
- Click the Query Builder button.
- In the Add Table dialog select "Product", "ProductInventory", "ProductPhoto" and "ProductProductPhoto" from the list of tables. Note: You can hold down the control key and click each of the tables to select them all at one time.
- Click the Add button to close the dialog.
- On the Query Builder select the fields shown in the figure below. In the Product table select "Name", "ProductNumber" and "ReorderPoint". In ProductPhoto select the "ThumbNailPhoto" column. In the ProductInventory table select the "Quantity" column.
- Click the OK button to close the dialog.
- The Configure Data Source Command step would show the generated statement. Clicking the Next button would lead you to the Preview Data Source Results step, where you can preview the data. Click finish to return to the Choose Data Source page of the Report Wizard. On the next page choose Standard Report Type and click the Next button.
- The Design Data Layout page of the Report Wizard allows you to assign database fields to sections of the report. The Report Wizard automatically places and formats the database fields in the appropriate report sections.
- Select from the Available Fields list on the left side of the page.
- Select "Name", "ProductNumber", "ReorderPoint" and "Quantity".
- After selecting each field, click the Detail button to add those columns to the detail listing of the report.
- Click the Next button.
- On the Choose Report Layout page of the Report Wizard unselect the Adjust report items to fit available space checkbox. Click the Next button.
- On the Choose Report Style page of the Report Wizard select "Civic" from the Style Sheets list on the left side of the page. Notice the style changes in the Preview portion on the right side of the page.
- On the Completing the Wizard page of the Report Wizard you can review the settings for the report and click the Finish button
The initial report layout appears in the design view in Visual Studio.
Note Notice that the wizard has automatically provided:
- Data bound fields in the detail section of the report.
- Styled page and column titles.
- A page footer with standard date and page number output.
- Rebuild the project.
- Click the Preview tab of the designer to view your report.
如果要使用函数或者report Paremeter的话
可以右击report空白处设置一个parameter,然后在在design窗口中选择expression项,双击函数或者parameters
如图: