开发者

Dynamically Setting up ReportViewer

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开发者_JS百科 { 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜