使用reportviewer将参数从页面传递到rdlc [英] Pass parameter to rdlc from page with reportviewer
问题描述
我有一个Visual Studio 2013 Web应用程序,可与实体框架一起使用,我想使用RDLC报告显示简单的表格数据报告。
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.
我创建了一个单独的网页并添加了一个reportviewer控件。我还创建了RDLC文件,并从C#函数添加了数据源,该函数返回了自定义对象的 List
。这样可以从报表设计器进行配置,但是当页面在浏览器中加载时,错误尚未提供数据源'DataSet1'
的数据源实例。 。
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.
报告设计
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 建议,我添加了以下代码,现在该报告起作用了。
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)));
}
}
请帮助我解决此问题。我只需要显示一个使用RDLC的简单报告,数据源是一个公共静态函数,带有一个返回对象列表的参数。
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.
推荐答案
您是否在页面加载中设置了数据源?
Have you set the data source in the page load?
YourReportViewer.LocalReport.DataSources.Add(new ReportDataSource("testDataSet", list));
这篇关于使用reportviewer将参数从页面传递到rdlc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!