Set DataBand DataSource at Runtime

Stimulsoft Reports.WEB discussion
Post Reply
admin@secsol.co.uk
Posts: 70
Joined: Wed Jun 01, 2022 8:26 am

Set DataBand DataSource at Runtime

Post by admin@secsol.co.uk »

Is there anyway to change the DataSource for a DataBand at runtime - during the report production.

I tried using :

Code: Select all

If (Info.DatabaseSelected == 1)
   HeaderDataBand,DataSource = FavouriteHeaderMechanical
 
Where Info is a business object.

Basically I want one report to work for either database and be selected by a value in a business object. Is this possible?
Attachments
PrtScr capture.jpg
PrtScr capture.jpg (190.23 KiB) Viewed 479 times
Lech Kulikowski
Posts: 7595
Joined: Tue Mar 20, 2018 5:34 am

Re: Set DataBand DataSource at Runtime

Post by Lech Kulikowski »

Hello,

You can use the following code:
var databand = report.GetComponentByName("DataBand1") as StiDataBand;
databand.DataSourceName = "DataSourceName";

Thank you.
admin@secsol.co.uk
Posts: 70
Joined: Wed Jun 01, 2022 8:26 am

Re: Set DataBand DataSource at Runtime

Post by admin@secsol.co.uk »

Thanks for that.

How do I change the field within the databand to pick up the new data source?

i.e. in the field above it is picking up FavouriteHeaderElectrical.MainDescription - I tried changing it to be dataField.Text = FavouriteHeaderMechanical.MainDescription but it still used the old data source.

Is there any way to set a data field to automatically just use the databand data source i.e. dataField.Text = dataBand.DataSource.MainDescription?
Lech Kulikowski
Posts: 7595
Joined: Tue Mar 20, 2018 5:34 am

Re: Set DataBand DataSource at Runtime

Post by Lech Kulikowski »

Hello,

Unfortunately, no. You should change the expression; there are no automatic methods.

Thank you.
Post Reply