ReportViewer使用及注意事項


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM