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

Binding collection of simple types (e.g. List<String>)

3 Answers 873 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Monsignor
Top achievements
Rank 2
Monsignor asked on 27 Aug 2010, 07:51 AM
HI,

I want to share my experience with binding an IEnumerable<String> to a report.

Normally, you bind a collection of complex objects with public properties:
public sealed class MyType
{
  public String FirstName { get; set; }
  public String LastName { get; set; }
}
 
 
report.DataSource = new List<MyType>();

Then, in a report's textbox, you specify this expression to load the data from MyType object:
= Fields.FirstName + " " + Fields.LastName



But what if you want to just bind a list of strings without creating redundant wrapper types?
report.DataSource = new List<String>();

You can't just set "= Fields" expression to a textbox, it will produce "Incorrect use of Fields" exception. But you can set following expression and it will work (RawData is of type Object, so I guess it calls ToString() method internally):
= ReportItem.DataObject.RawData

3 Answers, 1 is accepted

Sort by
1
Accepted
Steve
Telerik team
answered on 30 Aug 2010, 04:40 PM
Hello Monsignor,

You can use = Fields.Item as well which is meant for such purpose.

Sincerely yours,
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
0
Ashok
Top achievements
Rank 1
answered on 31 Mar 2019, 08:52 AM

Really helped me.

Thanks

0
Vic
Top achievements
Rank 2
answered on 17 Jun 2020, 12:01 PM
Thank you Monsignor and Steve. It helped greatly.
Tags
General Discussions
Asked by
Monsignor
Top achievements
Rank 2
Answers by
Steve
Telerik team
Ashok
Top achievements
Rank 1
Vic
Top achievements
Rank 2
Share this question
or