I have a main report having subreport whose reportsource has to be set dynamically based on the field value (Response type) of the sqldatasource of mainreport ,
I tried to get the value of Responsetype from the dataobject in detail_itemdatabinding event and stored in a variable .
I subreport_itendataBinding event tried to set Telerik.Reporting.SubReport.reportsource to new object of TypeReportSource class, then invalidcastexception is ocurring
Unable to cast object of type 'Telerik.Reporting.Processing.SubReport' to type 'Telerik.Reporting.SubReport
'Telerik.Reporting.Processing.SubReport does not have REportsource property so i used Telerik.Reporting.SubReport, but exception is happening
Kindly assist on this issue
public partial class InterviewReport : Telerik.Reporting.Report
{
protected string reportSourceValue = "";
public InterviewReport()
{
//
// Required for telerik Reporting designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
private void detail_ItemDataBinding(object sender, System.EventArgs e)
{
Telerik.Reporting.Processing.DetailSection item =
(Telerik.Reporting.Processing.DetailSection)sender;
object o = item.DataObject["ResponseType"];
if (o is string)
{
if (string.Equals(o, "Text Response"))
{
this.reportSourceValue = "ReportLibrary.Reports.Response, ReportLibrary, Version=1.0.0.0, Culture=neutral, " +
"PublicKeyToken=null";
}
else if (string.Equals(o, "Check Box"))
{
this.reportSourceValue = "ReportLibrary.Reports.ReportCheckBox, ReportLibrary, Version=1.0.0.0, Culture=neutral, " +
"PublicKeyToken=null";
}
}
}
private void subReport1_ItemDataBound(object sender, System.EventArgs e)
{
// Telerik.Reporting.Processing.ReportItemBase item =
// (Telerik.Reporting.Processing.ReportItemBase)sender;
Telerik.Reporting.SubReport sub = (Telerik.Reporting.SubReport)sender;
Telerik.Reporting.TypeReportSource typeReportSource2 = new Telerik.Reporting.TypeReportSource();
typeReportSource2.Parameters.Add(new Telerik.Reporting.Parameter("LocalEngID", "= Parameters.LocalEngID.Value"));
typeReportSource2.Parameters.Add(new Telerik.Reporting.Parameter("InterviewQuestionsID", "=Fields.InterviewQuestionsID"));
typeReportSource2.TypeName = reportSourceValue;
sub.ReportSource = typeReportSource2;
}
}
Regards,
Mary Jain