This example shows how to set variable value from code. First, load scripts:
@using Stimulsoft.Base
@using Stimulsoft.Report
@using Stimulsoft.Report.Blazor

Next, create buttons:
<div align="center">
    <input type="text" @bind="newValueInput" />
    <button class="alert" @onclick="SetVariable">Set variable</button>
</div>

Then, add report viewer:
<div align="center">
    <StiBlazorViewer Report="@Report" />
</div>

After that, create empty report object and load report template:
@code
{
	private StiReport Report;
	private string newValueInput;

 	protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

		//Create empty report object
		this.Report = new StiReport();

		//Load report template
		var reportBytes = await Http.GetByteArrayAsync("Reports/ReportWithVariable.mrt");
		this.Report.Load(reportBytes);
	}

...

Then, create method to set variable:
...

	private void SetVariable()
    {
	 	//Get a copy of the report into a new report object
        var report = this.Report.Clone() as StiReport;
        
		//Set new value
        report["MySuperUselessVariable"] = newValueInput;

        //Update view
        report.Render();
		
		//Assign new report to the viewer
		this.Report = report;
    }
}

In the screenshot below you can see the result of the sample code:

Using Report Variables in Code

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.