Link to home
Start Free TrialLog in
Avatar of arvee2003
arvee2003

asked on

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>
Avatar of Rahul Agarwal
Rahul Agarwal
Flag of India image

ASKER CERTIFIED SOLUTION
Avatar of arvee2003
arvee2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arvee2003
arvee2003

ASKER

NO comments
No comments
Figured it myself