3

我对 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 
} 

}   
4

1 回答 1

0

我想指出您没有使用:

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

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

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

希望这可以帮助。

于 2013-08-13T17:43:06.917 回答