本地报道。 GetTotalPages()始终返回0

时间:2013-08-12 12:52:46

标签: winforms report reportviewer localreport

我遇到了Microsoft.Reporting.WinForms.LocalReport的问题。方法GetTotalPages()即使在渲染和保存文件后也始终返回零。报告生成并正确保存。求助。

foreach (DataSet.PersonsRow person in dataSet.Persons.Rows)
{ 

DataSet.PersonsDataTable persons = new DataSet.PersonsDataTable(); 
persons.ImportRow(person); ReportViewer rv = new ReportViewer(); 
string mimeType, encoding, fnameExtension; 
string[] streamids; Warning[] warnings;
rv.ProcessingMode = ProcessingMode.Local; 
rv.LocalReport.ReportPath = "ReportTemplates\\report.rdlc";
rv.LocalReport.SetParameters(new ReportParameter("Parameter", Settings.Parameter.ToString()));
rv.LocalReport.DataSources.Add(new ReportDataSource(dataSet.persons.TableName, (DataTable)persons)); 
rv.LocalReport.DataSources.Add(new ReportDataSource(dataSet.Profile.TableName, (DataTable)dataSet.Profile));
rv.LocalReport.DataSources.Add(new ReportDataSource(dataSet.Places.TableName, dataSet.Equipment.Where(tc => tc.PersonID == person.PersonID)));
byte[] bytes = rv.LocalReport.Render(OutputTypeStr, "<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>", out mimeType, out encoding, out fnameExtension, out streamids, out warnings);

int pagesCount = rv.LocalReport.GetTotalPages(); // pagesCount equal zero 
using (FileStream fs = new FileStream(filename, FileMode.Create)) 
{
    fs.Write(bytes, 0, bytes.Length);
    fs.Close(); 
    pagesCount = rv.LocalReport.GetTotalPages(); // pagesCount also equal zero 
} 

}   

1 个答案:

答案 0 :(得分:0)

我想指出你没有使用:

Microsoft.Reporting.WinForms.LocalReport.GetTotalPages(); 

但是

Microsoft.Reporting.WinForms.ReportViewer.LocalReport.GetTotalPages(); 

如果不使用它,为什么要创建LocalReport lr

希望这有帮助。