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

Binding "DataSource" Property

7 Answers 1665 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Darnell
Top achievements
Rank 1
Darnell asked on 06 Oct 2013, 11:15 AM
I am trying to make the report datasource dynamic by binding the "DataSource" property to a report parameter but it doesn't seem to accept no matter what i put in the Binding expression.

As per the online documentation http://www.telerik.com/help/reporting/ui-edit-bindings.html, DataSource is a valid property path.

I tried binding it to the literal name of my datasource (instead of parameter or expression) but still doesn't work.
<Bindings>
  <Binding Path="DataSource" Expression="MySQLSourceName" />
</Bindings>


Has anyone tried this before and can confirm that it worked?

Thanks!


7 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 09 Oct 2013, 02:27 PM
Hi Darnell,

The binding you have set is not valid, but is logically equivalent to setting the report's DataSource property to the SqlDataSource component named MySQLSourceName. Using bindings you can set the DataSource to an expression that can be evaluated as a valid data object e.g. field linking a collection.

If you need to change the report's DataSource you will have to reassign it. There are forum threads discussing such dynamic data changes as:

In order to provide you more accurate suggestions, please elaborate on the required dynamic DataSource change - what and how should be changed and how it reflects the report.

Regards,
Stef
Telerik

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

0
Darnell
Top achievements
Rank 1
answered on 09 Oct 2013, 02:51 PM
Thanks for the reply Stef.

MySQLSourceName is actually an SqlDataSource component's name in my report. Here's the scenario:

I have two SqlDataSource components in my report. SqlSource1 and SqlSource2. Then I have a report parameter named TheSqlSource. I then bind the report's DataSource property using this expression =Parameters.TheSqlSource.Value.

Then in my C# code I passed the parameter's value:

var theSqlSource = GetDataSourceName();
ReportViewer1.ReportSource.Parameters.Add("TheSqlSource", theSqlSource);

At first I thought the report is receiving an invalid SqlDataSource name from the parameter, but then i tried removing the parameter and entered the SqlDataSource name directly in the binding expression and it still didn't work.


0
Stef
Telerik team
answered on 14 Oct 2013, 02:06 PM
Hello Darnell,

Changing the report's DataSource using binding to a report parameter providing the name of the data source component will not work, as the expression is evaluated as if you have set myReport.DataSource="string".

You can use custom UI to allow the user to select the data source for the report. Thus you can assign the data prior to displaying it e.g.:
var report = new MyReport();
report.DataSource = GetData(userSelection);
 
ReportViewer.ReportSource= new InstanceReportSource { ReportDocument = report };

If you prefer to use the report parameters, you can reset the report DataSource which will cause its NeedDataSource event to be fired. Then you can provide the data in the events handler based on the running parameter's value as illustrated in the Using Report Events help article.

i hope this helps you.

Regards,
Stef
Telerik

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

0
Curt Rabon
Top achievements
Rank 1
Veteran
answered on 08 May 2020, 02:53 PM

I need to dynamically provide a ConnectionString to a .trdp at runtime.

I've tried to use a parameter and a binding as stated here: https://docs.telerik.com/reporting/knowledge-base/how-to-pass-connectionstring-to-report-dynamically-through-report-parameter

but I can't get it to work. Without the parameter and binding, the existing dataSource works fine in preview. I'm using Standalone Report Designer 13.2.19.1213. When I add the parameter and binding, and put the connection string value in the parameter input box during preview, I get an error. See the attached picture that shows all settings.

0
Neli
Telerik team
answered on 13 May 2020, 06:38 AM

Hi Curt,

From the error message, it seems that the connection string is not correct. There might be a syntax error. Make sure that the connection string that you are passing from the report parameter is the right one. If the issue is not solved, consider sending us the report and database.

Regards,
Neli
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Curt Rabon
Top achievements
Rank 1
Veteran
answered on 13 May 2020, 02:32 PM
After looking carefully at https://docs.telerik.com/reporting/expressions-bindings, I noticed that I did not start the binding's expression value with an equal sign, so instead of =Parameters.ConnectionStringParam.Value, I only had Parameters.ConnectionString.Value. I fell into this trap because your page at https://docs.telerik.com/reporting/knowledge-base/how-to-pass-connectionstring-to-report-dynamically-through-report-parameter does not show the equal sign in your example. I suggest showing the equal sign or reminding people that it's needed.
After using the equal sign, the report parameter works fine, and I can dynamically switch the connection string.
0
navi
Top achievements
Rank 1
Iron
answered on 03 Aug 2021, 12:53 PM | edited on 04 Aug 2021, 08:57 AM
m
Tags
General Discussions
Asked by
Darnell
Top achievements
Rank 1
Answers by
Stef
Telerik team
Darnell
Top achievements
Rank 1
Curt Rabon
Top achievements
Rank 1
Veteran
Neli
Telerik team
navi
Top achievements
Rank 1
Iron
Share this question
or