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

Incorrect usage of Parameters object

1 Answer 82 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 20 Mar 2013, 01:51 PM
Hi,

I'm trying to use a custom function in my expression to decide what field should be displayed in the textbox, what grouping should be done, what formatting style should be applied, visibility and how the drilldown functions work.

So far I got here (example of displaying text)
C#
public static string GroupDisplay(int GroupNumber, Telerik.Reporting.ReportParameterCollection parameters, decimal? RecordCenterKey, decimal? RecordUserKey, DateTime? BillDT_DateTime, decimal BillDT) {
            switch (GetGroupingForGroupNumber(GroupNumber)) {
                case ReportGrouping.None:
                    return string.Empty;
                case ReportGrouping.Centers:
                    return CenterName(GetCenterKeyFromParameters(parameters), RecordCenterKey, GetViewSubCentersFromParameters(parameters));
                case ReportGrouping.Users:
                    return CreateUserName(RecordUserKey);
                case ReportGrouping.Date:
                    return CheckDate(GroupDate(BillDT_DateTime, BillDT));
                default:
                    return string.Empty;
            }
        }

My expression:
= GroupDisplay(1, Parameters, Fields.TxTicket_CenterKey, Fields.TxTicket_UserKey_BilledByKey, NULL, Fields.TxTicket_BillDT)

The reason why I am using the Telerik.Reporting.ReportParameterCollection instead of using every parameter separately is because there are 7 default parameters and many optional depending on the report, I want to use the same expression in all 40 so if something changes I can change the expressions in code for all of them in no time.

Am I using a bad approach to solve this or is it something that is not possible in the current release of Telerik Reporting

Kind regards,
Frank

1 Answer, 1 is accepted

Sort by
0
Sven J
Top achievements
Rank 2
answered on 25 Aug 2015, 12:41 PM

Hi,

2+ years later, same problem. Got around it using ​report's ​code ​behind file like this:

 

Report.ItemDataBinding += (sender, e) =>
            {
                // get processing report instance
                var report = (Telerik.Reporting.Processing.Report) sender;
                
                // convert to simple dictionary
                var ods = new ObjectDataSourceParameter("parameters"
                    , typeof(IDictionary<string, object>)
                    , report.Parameters.ToDictionary(rp => rp.Key, rp => rp.Value.Value));

                // Transfer ReportParameter values to the repository
                if (!​Repository.Parameters.Any())
                    ​Repository.Parameters.Add(ods);
                else
                    Repository.Parameters[0] = ods;
            };

Object called Repository is my (Object)DataSource. It has a Method which takes an IDictionary<string,object>. This holds all ​report parameters with current values.

Tags
General Discussions
Asked by
Frank
Top achievements
Rank 1
Answers by
Sven J
Top achievements
Rank 2
Share this question
or