SubReport is not working after adding parameter

拜拜、爱过 提交于 2019-11-30 09:57:15

问题


I am working on RDLC report On VS2012

When I am trying add a parameter on my Sub report then my report is not working and I am getting this error “Error: Sub report could not be shown.”

And after adding parameter this event LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e) is not even called.


回答1:


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.

in Page_Load I added

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

then in I added the event

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));
}

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

Things finally started working when I added

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

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



来源:https://stackoverflow.com/questions/14494933/subreport-is-not-working-after-adding-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!