0

I have a visual studio 2013 web application which works with entity framework and I want to display a simple tabular data report using a RDLC report.

I have created a seperate web page and added a reportviewer control. Also I have created a RDLC file and added the data source from a C# function which returns a List of custom objects. This way it is configurable from the report designer, but when the page loads in the browser an error A data source instance has not been supplied for the data source 'DataSet1' is shown.

Report design enter image description here

HTML markup

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
        WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
        <LocalReport ReportPath="Alumni\Reports\Report1.rdlc"></LocalReport>
    </rsweb:ReportViewer>

For above implementation I got the error of not giving a data source, but as Yuliam Chandra suggested, I added the below code and now the report works.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", Business.ReportManager.GetMemberDetails(1)));
        }
    }

Please help me to solve this issue. I just need to display a simple report using RDLC and the data source is a public static function with an argument which returns a list of objects.

Community
  • 1
  • 1
Sandun Perera
  • 541
  • 6
  • 21

1 Answers1

3

Have you set the data source in the page load?

YourReportViewer.LocalReport.DataSources.Add(new ReportDataSource("testDataSet", list));
Yuliam Chandra
  • 14,494
  • 12
  • 52
  • 67
  • Since I have added data source and data set in the report designer and the report also designed using the data set fields. Do I need to specify a data source again in the page load? – Sandun Perera Jul 26 '14 at 09:08
  • Show your reportviewer in the aspx and update it in your question – Yuliam Chandra Jul 26 '14 at 09:20
  • Hi Yuliam Chandra, I have updated the question and I got the report to work with using your given syntax. Can you explain why we need to explicitly give the same data source again in the code behind. Thanks! – Sandun Perera Jul 26 '14 at 13:12
  • @SandunPerera, based on html markup you just updated, you don't provide any datasource when specifying `LocalReport`, you can either set in the markup by adding `` inside `` then also provide the target data source in the markup` like `` OR set the data source in the code behind just like you did – Yuliam Chandra Jul 26 '14 at 13:22
  • Thanks Yuliam Chandra, I choose to proceed with code behind approach which will give me more control over loading the data to the report. – Sandun Perera Jul 26 '14 at 13:26
  • 1
    @SandunPerera, you can also specify the report name in the code behind like `ReportViewer1.LocalReport.ReportEmbeddedResource = "TheProjectName.Report1.rdlc"`, but remove the `` in the aspx, this way you can switch multiple reports with single viewer.. – Yuliam Chandra Jul 26 '14 at 13:32