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

ReportParameter Bind to Enum

2 Answers 265 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stuart
Top achievements
Rank 1
Stuart asked on 05 May 2010, 05:45 PM
Hi,

Is it possible to bind a ReportFilter.In operator's datasource to an Enum? e.g.

parameter.AvailableValues.DataSource = Enum.GetNames(typeof(CompletionStatus));

I am binding to an ICollection of DTO's hence the field value will be an enum. 

I get the following error:

The expression contains object 'CompletionStatus' that is not defined in the current context.



Many thanks

2 Answers, 1 is accepted

Sort by
0
Hrisi
Telerik team
answered on 10 May 2010, 03:41 PM
Hi Stuart,

Unfortunately the info you have provided is not enough to help us fully understand what you want to achieve. Data binding to objects is documented in ObjectDataSource Component help section. In order to use Enum for datasource you can convert it to supported object types.

In your case Enum.GetNames(typeof(CompletionStatus)) will return array strin[], which is a supported type. Items in the array can be accessed in the expressions in this manner: =Fields.Item.

To clarify our understanding of the problem, please preview the attached example report. The report DataSource uses a ObjectDataSource and the filter uses In operator.

Kind regards,
Hrisi
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
Stuart
Top achievements
Rank 1
answered on 10 May 2010, 11:14 PM
Thanks, that really helped.

I had originally started using some EnumWrapper class but actually this works for me:

            this.ReportParameters["MyParam"].AvailableValues.DataSource = Enum.GetNames(typeof (MyEnum));
            this.ReportParameters["MyParam"].AvailableValues.ValueMember = "= Fields.Item";
            this.ReportParameters["MyParam"].AvailableValues.DisplayMember = "= Fields.Item";

Where the Filter is defined as:

this.Filters.AddRange(new Telerik.Reporting.Data.Filter[] {
            new Telerik.Reporting.Data.Filter("=Fields.Property3.ToString()", Telerik.Reporting.Data.FilterOperator.In, "=Parameters.MyParam.Value")});

Obviously here I am filtering by the name of the Enum but that is fine for this scenario
Tags
General Discussions
Asked by
Stuart
Top achievements
Rank 1
Answers by
Hrisi
Telerik team
Stuart
Top achievements
Rank 1
Share this question
or