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

Use index in "=Fields." for report control value

10 Answers 1646 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sven
Top achievements
Rank 1
Sven asked on 20 Jul 2012, 01:20 PM
Hi,
is it possible to bind a report controls value to an index value like
=Fields.Data[0]

In my report I have a table that is bound to an objectdatasource. I want to bind some of the tables columns to a list of values in the objects using an indexer. Can that be done? I haven't found a way so far.

Thx

10 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 23 Jul 2012, 05:50 PM
Hello Patrick,

In order to handle array values in an expression, our suggestion is to utilize an user function. Check out the following sample:

public static string GetItemValue(string[] values, int index)
{
    return values[index];
}

Then you can use the following expression:
=GetItemValue(Fields.Data,0) Kind regards,
Peter
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Craig
Top achievements
Rank 1
answered on 23 Oct 2013, 07:02 PM
Hmm, this doesn't appear to be working anymore. When I place the function in the code-beside for the report and try to run the report in preview an error appears "GetItemValue is not defined".
0
Stef
Telerik team
answered on 24 Oct 2013, 05:10 PM
Hi Craig,

Please take a look at the The expression contains undefined function call MyUserFunction() error KB article.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 02 Dec 2013, 01:26 AM
Hello,

My function work fine but Data seem not working....   And I need using fields by index.

This is my expression with my valid function ;

{Rapports.methodesCommunes.GetItemValue(Fields.Data, 1)}

See attachement.
0
Nasko
Telerik team
answered on 02 Dec 2013, 01:22 PM
Hello Louis,

Fields.Data is a field coming from the data source, not a system reserved field. It is used by the original poster in the same way as Fields.SomeField is used in other examples.

Also this thread is about how to use indexers in fields containing objects i.e., Fields.SomeField[1]. If I understand correctly, you are trying to use indexer with the Fields collection itself i.e., Fields[1], which is another matter and is currently not possible.

Regards,
Nasko
Telerik

New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

0
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 02 Dec 2013, 01:59 PM
Hello Nasko,

Thank you for the answer.

Exactly, I need to get the value of the first field without using the name of the field.

It's possible to get in C# in the event DataBound of the textbox (with a dataset or else)?


0
Nasko
Telerik team
answered on 05 Dec 2013, 11:39 AM
Hello Louis,

Indeed it is possible to access the data objects of a processing item in an event using the ProcessingElement.DataObject Property, but you will still be required to pass the name of the desired field as an indexer value. Thus, you cannot get the value of the first field without using the name of the field.

Still if you need additional assistance please elaborate further on your data schema model and scenario.

Regards,
Nasko
Telerik

New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

0
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 05 Dec 2013, 02:22 PM
Too bad.  Thank you.
0
Elliot
Top achievements
Rank 1
answered on 15 Nov 2016, 02:54 PM

I have a report where the datasource has a firstname and lastname field.  I want to bind the title to use the firstname and lastname from the first record in the datasource.  To do added the following function to the report code:

public static string GetItemValue(string[] values, int index)
{
   return values[index];
}

And set the title textbox value to:

= GetItemValue(Fields.FirstName,0) + " " + GetItemValue(Fields.LastName,0)

But I get the following error:

Type mismatch in function arguments.Cannot find an overload of the function GetItemValue that accepts arguments of type (String, Int32).

Can you tell me how I would correct this.

0
Katia
Telerik team
answered on 15 Nov 2016, 04:47 PM
Hello Elliot,

This error occurs as the function GetItemValue() accepts array of strings as a first parameter (not ). When you pass Fields.FirstName which is of type string as a parameter for this function, the exception is thrown.

To get the first record from the data source you can use First() aggregate function, for example:
= First(Fields.FirstName) + " " + First(Fields.LastName)


Regards,
Katia
Telerik by Progress
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 Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Sven
Top achievements
Rank 1
Answers by
Peter
Telerik team
Craig
Top achievements
Rank 1
Stef
Telerik team
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Nasko
Telerik team
Elliot
Top achievements
Rank 1
Katia
Telerik team
Share this question
or