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 void OnInitialized()
{
base.OnInitialized();
//Create empty report object
this.Report = new StiReport();
//Load a report template
this.Report.Load("Reports/ReportWithVariable.mrt");
}
...
Then, create method to set variable:
...
private void SetVariable()
{
//Get a copy of the report into a new report object
var report = this.Reports.Clone() as StiReport;
//Set new value
report["MySuperUselessVariable"] = NewValueInput;
//Render report with new value
report.Render();
//Assign new report to the viewer
this.Report = report;
}
}
In the screenshot below you can see the result of the sample code: