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;
}
}
На скриншоте ниже Вы можете увидеть результат выполнения данного кода: