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_Selec tedIndexCh anged 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. SubreportP rocessing += new SubreportProcessingEventHa ndler(Loca lReport_Su breportPro cessing);
}
void LocalReport_SubreportProce ssing(obje ct sender, SubreportProcessingEventAr gs e)
{
string strParameter = e.Parameters["person_id"]. Values[0]. ToString() ;
ReportDataSource rdsSubreport = new ReportDataSource("dsTraini ng_dtTrain ing", getTrainingData(strParamet er));
e.DataSources.Add(rdsSubre port);
}
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. DataSource s.Clear();
ObjectDataSource1.SelectPa rameters.C lear();
ReportViewer1.ProcessingMo de = ProcessingMode.Local;
// Set the Report Datasource
ReportViewer1.LocalReport. ReportPath = "Reports/DetailReportWithT raining.rd lc";
ReportDataSource rds = new ReportDataSource();
rds.Name = "dsDetail_dtDetail";
rds.Value = dtData;
ReportViewer1.LocalReport. DataSource s.Clear();
ReportViewer1.LocalReport. DataSource s.Add(rds) ;
// Set Report Parameters based on Report Selection
ReportParameter[] rptParameters = new ReportParameter[2];
ReportParameter param1 = new ReportParameter("reportTit le", reportTitle);
ReportParameter param2 = new ReportParameter("reportTyp e", groupType);
rptParameters[0] = param1;
rptParameters[1] = param2;
ReportViewer1.LocalReport. SetParamet ers(rptPar ameters);
// Refresh the report
ReportViewer1.LocalReport. Refresh();
}
public DataTable getData(string groupby)
{
.....
return dsData.Tables[0];
}
protected void RadioButtonListGroup_Selec tedIndexCh anged(obje ct sender, EventArgs e)
{
String groupType = RadioButtonListGroup.Selec tedItem.Va lue;
switch (groupType)
{
case "A":
loadReport("A");
break;
case "N":
loadReport("N");
break;
}
// IF I UNCOMMENT THE FOLLOWING LINE IT WORKS
// ReportViewer1.LocalReport. SubreportP rocessing += new SubreportProcessingEventHa ndler(Loca lReport_Su breportPro cessing);
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="Cont entPlaceHo lder1" runat="Server">
<asp:RadioButtonList ID="RadioButtonListGroup" runat="server" AutoPostBack="true" style="clear:both"
RepeatDirection="Horizonta l" RepeatLayout="Table" CellSpacing="-1" CellPadding="-1" RepeatColumns="0" Enabled="True"
OnSelectedIndexChanged="Ra dioButtonL istGroup_S electedInd exChanged" >
<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\Detail ReportWith Training.r dlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSo urce1"
Name="dsDetail_dtDetail" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetData" TypeName="dsDetailTableAda pters.">
</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/requer y_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>
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_Selec
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.
}
void LocalReport_SubreportProce
{
string strParameter = e.Parameters["person_id"].
ReportDataSource rdsSubreport = new ReportDataSource("dsTraini
e.DataSources.Add(rdsSubre
}
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.
ObjectDataSource1.SelectPa
ReportViewer1.ProcessingMo
// Set the Report Datasource
ReportViewer1.LocalReport.
ReportDataSource rds = new ReportDataSource();
rds.Name = "dsDetail_dtDetail";
rds.Value = dtData;
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
// Set Report Parameters based on Report Selection
ReportParameter[] rptParameters = new ReportParameter[2];
ReportParameter param1 = new ReportParameter("reportTit
ReportParameter param2 = new ReportParameter("reportTyp
rptParameters[0] = param1;
rptParameters[1] = param2;
ReportViewer1.LocalReport.
// Refresh the report
ReportViewer1.LocalReport.
}
public DataTable getData(string groupby)
{
.....
return dsData.Tables[0];
}
protected void RadioButtonListGroup_Selec
{
String groupType = RadioButtonListGroup.Selec
switch (groupType)
{
case "A":
loadReport("A");
break;
case "N":
loadReport("N");
break;
}
// IF I UNCOMMENT THE FOLLOWING LINE IT WORKS
// ReportViewer1.LocalReport.
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="Cont
<asp:RadioButtonList ID="RadioButtonListGroup" runat="server" AutoPostBack="true" style="clear:both"
RepeatDirection="Horizonta
OnSelectedIndexChanged="Ra
<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\Detail
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSo
Name="dsDetail_dtDetail" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetData" TypeName="dsDetailTableAda
</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/requer
<asp:ImageButton ID="ImageButtonCancel" runat="server" CausesValidation="False"
OnClick="doCancel" ImageUrl="../Images/cancel
</div>
</div>
</asp:Content>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
NO comments
ASKER
No comments
ASKER
Figured it myself
http://www.sharepointpromag.com/article/aspnet2/asp-net-2-0-reporting
https://www.experts-exchange.com/questions/26264074/ReportViewer-and-Postback-problems.html
http://www.bigresource.com/Tracker/Track-ms_sql-2ujCh0mp/