问题
I want to dynamically setup the ReportViewer
at run time on a webform page.
My ReportViewer looks like this on the aspx page…
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"
Font-Size="8pt" Height="90%"
Width="100%" OnReportError="ReportViewer1_ReportError">
</rsweb:ReportViewer>
My class looks like this….
namespace S43G.CV
{
[Serializable]
public class CaseLoadForecastReportResultCV
{
public Int64 M3Fe { get; set; }
public Int64 M3Grad { get; set; }
public Int64 M6Grad { get; set; }
public Int64 M12Grad { get; set; }
public Int64 Total { get; set; }
public Int64 GroupPart { get; set; }
public Int64 Year { get; set; }
}
}
In the code behind I do the following to run the ReportViewer…
// get a list from db
List<CaseLoadForecastReportResultCV> answer = svyCaseBllHdl.GetCaseLoadForcastReport(userInput);
// Reset the ReportViewer
ReportViewer1.Reset();
ReportViewer1.LocalReport.Dispose();
ReportViewer1.LocalReport.DataSources.Clear();
// build the Report Data Source
ReportDataSource rds = new ReportDataSource("S43G_CV_CaseLoadForecastReportResultCV", answer);
// set new values for ReportViewer
ReportViewer1.LocalReport.ReportPath = "S4_Reports/CaseLoadForecast.rdlc";
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.LocalReport.Refresh();
The error I get is the following:
A data source instance has not been supplied for the data source 'CaseLoadForecastReportResultCV'.
Any help would be great.
回答1:
The name of your datasource in your RDLC is CaseLoadForecastReportResultCV
, you have some extra stuff appended to the front of its name. If you just change your code to this
ReportDataSource rds = new ReportDataSource("CaseLoadForecastReportResultCV", answer);
It should work. RDLC is XML and easy to read, you can read the datasources section in it, or load the report in Visual Studio and with the Report Designer focused, go to the Report menu and choose DataSources to see all the names of your data sources.
来源:https://stackoverflow.com/questions/1922744/dynamically-setting-up-reportviewer