先用設定好的DataSet(這裏叫Report.xsd)設定RDLC檔,以Report.rdlc為例。 接者在Asp.Net報表裏拉入Report Viewer,指向Report.rdlc,刪掉datasource那些用不到的東西,在aspx裏會看到類似 <rsweb:reportviewer id="ReportViewer1" runat="server" font-names="Verdana" font-size="8pt" height="400px" width="800px"> <LocalReport ReportPath="Report.rdlc"> </LocalReport> </rsweb:reportviewer> RDLC檔其實是一個xml,和Crystal Reports的rpt二進位格式大不同。用文字編輯器打開來看,會看到類似:<DataSet Name=" Report_ReportList "> 或是<DataSet Name> Report_ReportList </DataSet Name> 這裏Report是我在.xsd檔裏定義的DataSet名稱,而ReportList是table名稱,知道這個DataSet Name後,就可以動態改變RDLC的DataSource。 用我寫的程式片斷舉例: private void RefreshReport() { ReportViewer1.LocalReport.DataSources.Clear(); DataTable dt = getReportDataTable(); //這是我寫的private method ReportViewer1.LocalReport.DataSources.Add( new Microsoft.Reporting.WebForms.ReportDataSource(" Report_ReportList ", dt)); } 很簡單吧!只要加入一個ReportD...