ASP: Report Viewer Subreport not loading on post back

Hi,

I developed an asp report viewer page with a sub report and it works fine the first time.

I also have a radio button on the report viewer page which when clicked will change the
grouping of the report.

When the radio button is clicked the main report loads properly but the sub report does not
load. Looks like the subprocessing event is not called to load the data for sub report.

Error: Subreport could not be shown
I have enclosed relevant portions of the code.

NOTE: But if I uncomment the line in function RadioButtonListGroup_SelectedIndexChanged it works ok.

I would appreciate any help with this behavior or where & how should I handle the subreport
processing handler on post backs.

Thanks
Suresh

<script runat="server">
 
    DataTable dtData;
   
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            loadReport("N");
        }  

   // Add a subreport processing event handler
      ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);          
     }

    void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
    {
        string strParameter = e.Parameters["person_id"].Values[0].ToString();
        ReportDataSource rdsSubreport = new ReportDataSource("dsTraining_dtTraining", getTrainingData(strParameter));
        e.DataSources.Add(rdsSubreport);
    }

    public DataTable getTrainingData(string pid)
    {
        DataSet dsData = new DataSet();
      ....
        return dtTraining;        
    }
   
    protected void loadReport(string groupType)
    {            
        dtData = getData(groupType);

        // Reset Report Viewer Control
        ReportViewer1.Reset();
        ReportViewer1.LocalReport.DataSources.Clear();
        ObjectDataSource1.SelectParameters.Clear();
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
       
        // Set the Report Datasource
        ReportViewer1.LocalReport.ReportPath = "Reports/DetailReportWithTraining.rdlc";
 
        ReportDataSource rds = new ReportDataSource();
        rds.Name = "dsDetail_dtDetail";
        rds.Value = dtData;
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(rds);

        // Set Report Parameters based on Report Selection
     
        ReportParameter[] rptParameters = new ReportParameter[2];
        ReportParameter param1 = new ReportParameter("reportTitle", reportTitle);
        ReportParameter param2 = new ReportParameter("reportType", groupType);
        rptParameters[0] = param1;
        rptParameters[1] = param2;
        ReportViewer1.LocalReport.SetParameters(rptParameters);

        // Refresh the report
        ReportViewer1.LocalReport.Refresh();
    }
   
    public DataTable getData(string groupby)
    {
            .....
            return dsData.Tables[0];    
    }
    protected void RadioButtonListGroup_SelectedIndexChanged(object sender, EventArgs e)
    {
        String groupType = RadioButtonListGroup.SelectedItem.Value;
        switch (groupType)
        {
            case "A":
                loadReport("A");
                break;          
            case "N":
                loadReport("N");
                break;
        }

// IF I UNCOMMENT THE FOLLOWING LINE IT WORKS

// ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);    
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
            <asp:RadioButtonList ID="RadioButtonListGroup" runat="server" AutoPostBack="true" style="clear:both"
                                     RepeatDirection="Horizontal" RepeatLayout="Table"   CellSpacing="-1" CellPadding="-1" RepeatColumns="0"  Enabled="True"                   

OnSelectedIndexChanged="RadioButtonListGroup_SelectedIndexChanged">
                <asp:ListItem Value="A">Agency </asp:ListItem>
                <asp:ListItem Value="N">Name </asp:ListItem>
        </table>  
    </div>
    <div>
         <div > 
             <rsweb:ReportViewer ID="ReportViewer1" runat="server"   >
                 <LocalReport ReportPath="Reports\DetailReportWithTraining.rdlc">
                     <DataSources>
                         <rsweb:ReportDataSource DataSourceId="ObjectDataSource1"
                             Name="dsDetail_dtDetail" />
                     </DataSources>
                 </LocalReport>
             </rsweb:ReportViewer>
             <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
                 SelectMethod="GetData" TypeName="dsDetailTableAdapters.">
             </asp:ObjectDataSource>        
         </div>
    </div>    
    <div id="Div1">
                <br/>
                <div style="margin-left:325px">                  
                 <asp:ImageButton ID="ImageButtonRequery" runat="server" CausesValidation="False"
                      OnClick="doRequery" ImageUrl="../Images/requery_0.png" ToolTip="Click to Requery" />
                <asp:ImageButton ID="ImageButtonCancel" runat="server" CausesValidation="False"
                      OnClick="doCancel" ImageUrl="../Images/cancel_0.png" ToolTip="Click to Cancel" />
                   
                </div>
       </div>
</asp:Content>
arvee2003Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arvee2003Author Commented:
Did not help my requirements. But found it myself
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
arvee2003Author Commented:
NO comments
0
arvee2003Author Commented:
No comments
0
arvee2003Author Commented:
Figured it myself
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.