We were controlling the visibility of report items in the need data source event of the report by setting the visible property on the item like :
textbox1.Visible = false;
But after upgrade to Q3 2012 today, this has stopped working . But if we do this like below it works.
(this.Items.Find("textbox1", true)[0] as Telerik.Reporting.ReportItem).Visible = true;
Could you tell us as to why the old way wouldn't work anymore.
Thanks,
Sunita
6 Answers, 1 is accepted
For the latest release we have changed the way Telerik reports are serialized in out-proc session in order to eliminate a shortcoming. As you know, if you had modified the report definition outside the default constructor all changes were discarded because the report was recreated only by calling its default constructor. Now, with the new approach you can build a report definition entirely outside the constructor and it will be preserved exactly as it is in the Session.
The approach you have used till now has worked for you, but this has never been recommended, on the contrary, as listed in the Understanding Events help article, we've posted a warning not to modify the definition report item (the private field of the report class, i.e. this.textBox1) when working inside event handlers.
You've already found that getting the report item from the Items collection would do the job. Other options you have:
- Set the values by calling a method during or immediately after creating the report. This time the specific values will be preserved in the outproc session as is normally expected. You are no longer obliged to do this in the NeedDataSource event.
- Use report parameters and expressions which refer to them for the Textboxes values. Here you can use user functions as well.
Kind regards,
Steve
the Telerik team
HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!
All of our existing reports the subreport need datasource event is not getting fired.
A sample need data source event of a sub report we have is
private
void
SampleSubRpt_NeedDataSource(
object
sender, EventArgs e)
{
try
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Column1"
);
dt.Columns.Add(
"Column2"
);
dt.Columns.Add(
"Column3"
);
//Get the data then
foreach
(
object
[] cs
in
query)
{
DataRow dr = dt.NewRow();
dr[
"Column1"
] = cs[0];
dr[
"Column2"
] = cs[1];
dr[
"Column3"
] = cs[2];
dt.Rows.Add(dr);
}
Telerik.Reporting.Processing.SubReport samplesubrpt = sender
as
Telerik.Reporting.Processing.SubReport;
samplesubrpt.InnerReport.DataSource = dt;
}
catch
(Exception ex)
{
//
}
}
The code block above is called from the master/main report. We have the this.DataSource = null set on the subreport.
The InitializeComponent() in the main report also the following lines of code:
this
.SampleSubRpt.Name =
"SampleSubRpt"
;
instanceReportSource1.ReportDocument =
this
.sampleSubRpt1;
instanceReportSource1.Parameters.Add(
new
Parameter(
"SampleParameter"
,
"=Parameters.SampleParameter.Value"
));
this
.SampleSubRpt.ReportSource = instanceReportSource1;
this
.SampleSubRpt.NeedDataSource +=
new
System.EventHandler(
this
.SampleSubRpt_NeedDataSource);
How do I get the subrepeport to display the data and/or fire the need data source event.?
Thanks,
Sunita
And we are having this issue only after the upgrade to Q3 2012
This behavior again is caused by the report serialization in out-proc session. When the report is deserialized its items are recreated from scratch and the event handlers are lost. The only handlers that remain valid are those of the report itself. You can use them to re-attach the handlers of the subreport items using the approach from your initial post:
void
SampleRpt_NeedDataSource(
object
sender, System.EventArgs e)
{
var processingReport = (Telerik.Reporting.Processing.Report)sender;
var report = (Telerik.Reporting.Report)processingReport.ItemDefinition;
var subReport = (Telerik.Reporting.SubReport)report.Items.Find(
"subReport1"
,
true
)[0];
subReport.NeedDataSource +=
this
.SampleSubRpt_NeedDataSource;
}
void
SampleSubRpt_NeedDataSource(
object
sender, System.EventArgs e)
{
}
Still, our recommendation when designing reports is not to use any events. You can take advantage of the report parameters, declarative data source components, bindings, expressions, and user functions in order to handle various cases. If you need an advice for a particular case, please let us know.
You can also review our demo reports which demonstrate all of the above mentioned approaches.
Hope this helps.
Kind regards,
Chavdar
the Telerik team
HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to
use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!
Thanks,
Sunita
I am still having issues with the ItemDataBound event handlers in the subreports. These are not being called.
Is there a way to reattach them in the main report?
Thanks,
Sunita
We've already answered your inquiry in the support thread you have opened. Here is our reply:
You have two options. You can either use a TypeReportSource to reference the sub report from the SubReport item or you can handle the ItemDataBinding event of the sub report and attach the ItemDataBound event handlers of the items there. For example:
public
partial
class
DetailReport : Telerik.Reporting.Report
{
public
DetailReport()
{
InitializeComponent();
this
.ItemDataBinding +=
this
.DetailReport_ItemDataBinding;
}
void
DetailReport_ItemDataBinding(
object
sender, EventArgs e)
{
var textBox = (Telerik.Reporting.TextBox)(
this
.Items.Find(
"textBox1"
,
true
)[0]);
textBox.ItemDataBinding +=
new
EventHandler(textBox_ItemDataBinding);
}
public
void
textBox_ItemDataBinding(
object
sender, EventArgs e)
{
}
}
Hope this helps.
Regards,
Steve
the Telerik team
HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!