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

Passing parameters to the report with Silverlight

3 Answers 204 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pedro
Top achievements
Rank 1
Pedro asked on 19 May 2011, 07:33 PM
I'm passing parameters as stated in: http://www.telerik.com/support/kb/reporting/report-viewers/programmatic-initialization-of-report-parameter-values-in-telerik-reporting-silverlight-viewer.aspx

public PrintReport()
        {
            InitializeComponent();
            this.ReportViewer1.RenderBegin += new Telerik.ReportViewer.Silverlight.RenderBeginEventHandler(ReportViewer1_RenderBegin);
        }
void ReportViewer1_RenderBegin(object sender, Telerik.ReportViewer.Silverlight.RenderBeginEventArgs args)
{
    args.ParameterValues["ObjectTypeId"] = 40;
    args.ParameterValues["Page"] = 1;
    args.ParameterValues["PageSize"] = 10;
}


And trying to grab them in the server this way, but I get only null values. which is the correct way to do this ?

public partial class ObjectInstancesReport : Telerik.Reporting.Report
{
public ObjectInstancesReport()
{
                        InitializeComponent();

var objectTypeId = this.ReportParameters["ObjectTypeId"].Value == null ? 40 : (int)this.ReportParameters["ObjectTypeId"].Value;
var searchText = (string)this.ReportParameters["SearchText"].Value;
var page = this.ReportParameters["Page"].Value == null ? 1 : (int)this.ReportParameters["Page"].Value;
var pageSize = this.ReportParameters["PageSize"].Value == null ? 20 : (int)this.ReportParameters["PageSize"].Value;

3 Answers, 1 is accepted

Sort by
0
Ed
Top achievements
Rank 1
answered on 27 May 2011, 06:05 PM
Hello,

I am doing a similar thing.  I am passing in a parameter using this method.
The parameter seems to be getting into the report, but I'm trying to use a clever bit of code within my report to automatically switch the connection strings of my datasources - because we store client data in different databases.



        private List<SqlDataSource> _sqlDataSources;
        private List<SqlDataSource> SqlDataSources
        {
            get
            {
                if (_sqlDataSources == null)
                    BuildSqlDataSourceList();


                return _sqlDataSources;
            }
        }


        private void BuildSqlDataSourceList()
        {
            _sqlDataSources = new List<SqlDataSource>();
            var fields = GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            foreach (var field in fields)
            {
                if (field.FieldType == typeof(Telerik.Reporting.SqlDataSource))
                {
                    _sqlDataSources.Add((SqlDataSource)field.GetValue(this));
                }
            }
        }


        public void SetConnectionString(string connectionString)
        {
            foreach (var dataSource in SqlDataSources)
            {
                dataSource.ConnectionString = connectionString;
            }


        }  


At the top of the report I am calling my code to do this:
        public DemoDashboard()
               {
            //
            // Required for telerik Reporting designer support
            //

            InitializeComponent();
            SetConnectionString(SFSTelerikReport.GetConnectionString(this.ReportParameters["Company"].Value.ToString()));

I have the Company parameter intialised to a default.
This seems to work fine in the preview - the database changes when I change the valued of the parameter in the report but the problem is that it doesn't seem to work when I deploy it.  The connection strings seem to stay pointing at the Company that was in the parameters when I build it.

Why doesn't this work?

What I'm really after is an easy way of changing datasources at runtime.....


Thanks,
 Ed
0
Peter
Telerik team
answered on 30 May 2011, 02:02 PM
Hi Pedro,

We have noticed in the provided code snippet that you had used the Report Parameter definition item instead of the processing counterpart. The definition report parameter value is actually the default value. Thus our suggestion is to call the SetConnectionString method from report Itemdatabinding. The sender of the event is always the processing counterpart of the data item and you can use it to access the processing report parameter. For more information check out the Using Report Parameters programmatically.

Kind regards,
Peter
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
Ed
Top achievements
Rank 1
answered on 31 May 2011, 01:15 PM
Thanks, that worked exactly as I wanted it!

Ed
Tags
General Discussions
Asked by
Pedro
Top achievements
Rank 1
Answers by
Ed
Top achievements
Rank 1
Peter
Telerik team
Share this question
or