This is a migrated thread and some comments may be shown as answers.

Casting problem in subReport

1 Answer 111 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ciccio
Top achievements
Rank 1
ciccio asked on 15 Jun 2011, 01:22 PM
Hi,
I have the following statements in my report codebehind ( NeedDataSource) :

 

IEnumerable kl;   
kl =(IEnumerable)Report.ReportParameters[0].Value;   
List<string> ls = new List<string>();   
foreach (IEnumerable ie in kl)  
 
ls.Add((string)ie);   
}

It works fine.
But if this report is executed as a subreport from another Report i have :
Unable to cast object of type 'System.Char' to type 'System.Collections.IEnumerable'.
on foreach line.

so i tried :
IEnumerable kl;   
kl =(IEnumerable)Report.ReportParameters[0].Value;   
List<string> ls = new List<string>();   
foreach (var ie in kl)  
{  
ls.Add((string)ie);   
}

same problem, but now i can see the value of ie is the first char of the current kl element,
that is if the kl element is "Bye" ie value is "B". Then is obvious i get a casting eroor.
But why i have a different behaviour (report, subreport) and how to solve it?
Any idea?





1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 15 Jun 2011, 04:47 PM
Hi ciccio,

As you can see from the Using Report Parameters programmatically help article, whenever you're working with report parameters in events, you should use its processing counterpart i.e. instead of:

kl =(IEnumerable)Report.ReportParameters[0].Value;

should be:

Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
kl =(IEnumerable)report.Parameters["ParameterID"].Value;



Kind regards,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
ciccio
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or