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

Passing parameter to ObjectDataSource report

1 Answer 648 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 05 Jan 2016, 05:20 AM

Hi,

I'm trying to create a report programatically in C# using ObjectDataSource.

I've added a report parameter to the Report, and the parameter bar shows up on the right hand side.

I'm trying to pass the parameter from the report filer to my GetData class when the user clicks on "Preview" button. Can someone please help?

 

We first used the VS Telerik reporting wizard to create a Table report.

            this.RLDS.DataMember = "GetData";
            this.RLDS.DataSource = typeof(Test.TelerikReportLibrary.GenericTableDataSource);

            this.RLDS.Parameters.Add(
                            new Telerik.Reporting.ObjectDataSourceParameter("location", typeof(string), null));

namespace Test.TelerikReportLibrary
{
    [DataObject]
    public class GenericTableDataSource
    {
        [DataObjectMethod(DataObjectMethodType.Select)]
        public static List<AssetReportLine> GetData(string location) {
            var resultAssetList = new List<AssetReportLine>();
            // Get data from database
            return resultAssetList;
        }
    }
}

 

We tried to add a parameter so that it displays on the right hand side of the report.
var reportParameter1 = new Telerik.Reporting.ReportParameter();
reportParameter1.Name = "location";
reportParameter1.Text = "Enter Value for Parameter1";
reportParameter1.Type = Telerik.Reporting.ReportParameterType.Integer;
reportParameter1.AllowBlank = false;
reportParameter1.AllowNull = false;
reportParameter1.Value = "=10";
reportParameter1.Visible = true;
this.Report.ReportParameters.Add(reportParameter1);

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 06 Jan 2016, 02:22 PM
Hello Michael,

The data retrieval method's arguments can be mapped to report parameters. Please consider the example in Using Parameters with the ObjectDataSource Component.
this.RLDS.DataMember = "GetData";
this.RLDS.DataSource = typeof(Test.TelerikReportLibrary.GenericTableDataSource);
 
this.RLDS.Parameters.Add(
                          new Telerik.Reporting.ObjectDataSourceParameter("location", typeof(string), "=Parameters.location.Value"));

The recommended approach for creating report programmatically is to start with the Visual Studio Report Designer. By designing a sample report with test data, the VS Report Designer will generated code in the report's designer.cs(vb) file which can be modified and used at run-time.


I hope this information is helpful.

Regards,
Stef
Telerik
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
Michael
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or