Using Report Variables in Code
Our sample projects and report templates can help you learn the basics of working with our products.This example shows how to set variable value from code. First, load scripts:
Next, create buttons:
Then, add report viewer:
After that, create empty report object and load report template:
Then, create method to set variable:
In the screenshot below you can see the result of the sample code:

@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:
