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

Connecting to an indexer on an Object Data Source

1 Answer 92 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chick Leiby
Top achievements
Rank 1
Chick Leiby asked on 01 Jul 2011, 03:53 PM
I'm in the process of evaluating the Telerik reporting tool and am hitting a bit of a wall with something that I thought woudl be reasonably easy.  We currently use a generic class that holds an object array containing the data that is to be presented in a grid in the UI.  We then use an indexer on the class to access the appropriate value by positional index.  Since our end users have extensive flexibility in which columns can be included in their grids/reports and in what order, this is the simplest way for us to have a bindable object that does not have explicit property names.

We'd like to reuse this same object for a report, but I cannot for the life of me figure out how to set up an expression for a group/field that can access the indexer on the underlying business object.  If I use the normal c# indexer notation of, for example, "=[2]" then I get the error "The expression contains object '2' that is not defined in the current context." 

I tried adding a property called "Values" that exposed the object array and setting the expression to "=Values[2]" but that didn't help either.  Got the error "Missing operator before [2] operand."  Also tried "=Values.2" and that didn't help either ("Cannot interpret tocken '2' at position 7.").

Everything works find if I create explicit properties on the business object to expose the values in the array, but as I noted previously, this isn't a feasible solution.  So is this simply not possible with Telerik Reporting, or am I missing a subtle syntactical requirement?  Am I stuck having to take my existing list of business objects and convert them into a data table to use as the report's Data Source?

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 05 Jul 2011, 04:20 PM
Hi Chick Leiby,

Expressions use Telerik Reporting's built-in scripting language and currently we don't support indexer for collections. Still you can achieve your requirement with an user function as the following one:

public static string GetItemValue(string[] values, int index)
{
    return values[index];
}
We have attached a sample solution to illustrate the suggested approach. Regards,
Peter
the Telerik team
Register for the Q2 2011 What’s New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
Tags
General Discussions
Asked by
Chick Leiby
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or