且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

添加参数后,SubReport不起作用

更新时间:2023-12-03 14:02:58

我意识到我在这里参加聚会迟到了,但是在搜索过程中出现了这个问题,因此也许会对某人有所帮助.我终于在我的Web应用程序的主报告中找到了sup报告.

I realize that I'm late to the party here but this question came up during my searches so maybe this will help someone. I finally got sup reports working in my main report of my web application.

在我添加的Page_Load中

in Page_Load I added

ReportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WebForms.SubreportProcessingEventHandler(SetSubDataSource);
this.ReportViewer1.LocalReport.Refresh();

然后我添加了活动

public void SetSubDataSource(object sender, SubreportProcessingEventArgs e)
{
    var report = ((LocalReport)sender).DataSources[0];
    var tableid = e.Parameters["tableId"].Values[0];
    ObjectDataSource2.SelectParameters[0].DefaultValue = tableid;
    e.DataSources.Add(new ReportDataSource("DataSet2", ObjectDataSource2));
}

您还需要确保主报表的子报表具有正确定义的参数和数据以及子报表本身.这对我使用带有一个参数的存储过程有效,但是我认为一旦正确触发,就很容易添加其他参数.我还将子报表数据类型的常规选项设置为Integer(我的存储过程期望的类型),并允许为null,并将默认值设置为"Specify values",并将其保留为(Null).

You'll also need to make sure that your main report's sub report has the correctly defined parameter and data as well as the sub report itself. This works for me using a stored procedure with one parameter but I assume it's easy to add additional params once this is firing correctly. I also set the general options of my sub report data type to Integer (the type my sproc was expecting) and to allow nulls as well as set the default value as "Specify values" and left it as (Null).

当我添加

<SelectParameters>
    <asp:Parameter Name="tableId" Type="Int32" />
</SelectParameters>

在我的子报表的数据源对象的ObjectDataSource2节点内,您的行驶里程可能会有所不同.

inside the ObjectDataSource2 node of my sub reports data source object, your mileage may vary.