msdn中有详细的使用说明:http://msdn.microsoft.com/zh-cn/library/ms251671
在此记录一下。
个人感觉用起来还是很方便。而且效果很好,只是在数据源更新字段的时候比较折腾。
1、创建rdlc、数据源、aspx
aspx中 (将自己带出的dataset删除掉,这样来自己定义数据源,但是还是要建个xsd文件 作为数据源的套壳绑定到rdlc中)
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" Height="600px" Width="100%"> <LocalReport ReportPath="StatisticalQuery\report_ysk_tj.rdlc"> <DataSources> <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="Dataset_ysk_DataTable1" /> </DataSources> </LocalReport> </rsweb:ReportViewer>
创建rdlc和数据源
数据源的字段更改比较折腾, 我是把数据源改好后,rdlc直接用xml打开 将其中的字段改掉。
2、为reportviewer 绑定自定义数据源
DataTable dt = GetData(); ReportDataSource rds = new ReportDataSource("Dataset_ysk_DataTable1", dt); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(rds); ReportViewer1.LocalReport.Refresh();
可以很快的做个分组报表 并显示统计信息。
rdlc中的函数 有 count、sum、countdistinct等。。
注意发布后 web.config中有如下几项:
<compilation debug="false"> <assemblies> <add assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> <add assembly="Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> </assemblies> <buildProviders> <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </buildProviders> </compilation> <httpHandlers> <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false" /> </httpHandlers>
一般会引用两个dll
Microsoft.ReportViewer.WebForms
Microsoft.ReportViewer.Common