【问题标题】:Pass parameter to rdlc from page with reportviewer使用reportviewer从页面将参数传递给rdlc
【发布时间】:2014-09-18 02:13:20
【问题描述】:

我有一个使用实体框架的 Visual Studio 2013 Web 应用程序,我想使用 RDLC 报告显示一个简单的表格数据报告。

我创建了一个单独的网页并添加了一个报表查看器控件。我还创建了一个 RDLC 文件并从 C# 函数添加了数据源,该函数返回自定义对象的 List。这样,报表设计器就可以对其进行配置,但是当页面在浏览器中加载时,会显示错误A data source instance has not been supplied for the data source 'DataSet1'

报告设计

HTML 标记

    <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>

对于上述实现,我收到了未提供数据源的错误,但正如Yuliam Chandra 建议的那样,我添加了以下代码,现在报告工作了。

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

请帮我解决这个问题。我只需要使用 RDLC 显示一个简单的报告,数据源是一个公共静态函数,其参数返回一个对象列表。

【问题讨论】:

  • 如何将数据源从 C# 函数添加到 RDLC?请和谢谢你

标签: c# entity-framework reportviewer rdlc dynamic-rdlc-generation


【解决方案1】:

您是否在页面加载中设置了数据源?

YourReportViewer.LocalReport.DataSources.Add(new ReportDataSource("testDataSet", list));

【讨论】:

  • 由于我在报表设计器中添加了数据源和数据集,并且报表也使用数据集字段进行了设计。是否需要在页面加载时再次指定数据源?
  • 在 aspx 中显示您的报告查看器并在您的问题中更新它
  • 您好 Yuliam Chandra,我已经更新了问题,并且使用您给定的语法可以使用报告。你能解释一下为什么我们需要在后面的代码中再次显式地给出相同的数据源吗?谢谢!
  • @SandunPerera,基于您刚刚更新的html标记,指定LocalReport时不提供任何数据源,您可以通过在&lt;LocalReport&gt;&lt;/LocalReport&gt;中添加&lt;DataSources&gt;&lt;rsweb:ReportDataSource DataSourceId="TheNameOfTheDataSource" Name="testDataSet" /&gt;&lt;/DataSources&gt;来设置标记,然后也在标记中提供目标数据源,如&lt;asp:XXXDataSource ID="TheNameOfTheDataSource"&gt;&lt;/asp:XXXDataSource&gt; 或者像你一样在后面的代码中设置数据源
  • @SandunPerera,你也可以像ReportViewer1.LocalReport.ReportEmbeddedResource = "TheProjectName.Report1.rdlc"一样在后面的代码中指定报表名称,但是去掉aspx中的&lt;LocalReport&gt;,这样你就可以用一个查看器切换多个报表了..
猜你喜欢
  • 1970-01-01
  • 2020-09-23
  • 1970-01-01
  • 2017-03-08
  • 2013-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多