This example shows how to use a User Data object. First, load scripts:
@using Stimulsoft.Base
@using Stimulsoft.Report
@using Stimulsoft.Report.Blazor
@using Stimulsoft.Report.Web
Next, add report viewer:
<!--Report Viewer-->
<StiBlazorViewer Report="@Report" />
After that, create empty report object and load report template:
@code
{
//Report object to use in viewer
private StiReport Report;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
//Create report object and load template
this.Report = new StiReport();
var reportBytes = await Http.GetByteArrayAsync("Reports/UserData.mrt");
this.Report.Load(reportBytes);
...
Next, create user data and register it in the report template:
...
//Create user data
var stiUserData1 = new Stimulsoft.Report.Dictionary.StiUserData();
stiUserData1.Columns.AddRange(new Stimulsoft.Report.Dictionary.StiDataColumn[] {
new Stimulsoft.Report.Dictionary.StiDataColumn("Name", "Name", "Name", typeof(string), null),
new Stimulsoft.Report.Dictionary.StiDataColumn("Value", "Value", "Value", typeof(string), null)});
stiUserData1.Count = 5;
stiUserData1.GetData += new Stimulsoft.Report.Dictionary.StiUserGetDataEventHandler(stiUserData1_GetData);
//Register new data in the report template
this.Report.RegData("UserData", stiUserData1);
}
...
Finally, use user data arrays:
...
//User data arrays
private string[] nameArray = new string[] { "Mahesh Chand", "Mike Gold", "Raj Beniwal", "Praveen Kumar", "Dinesh Beniwal" };
private string[] valueArray = new string[] { "00", "01", "02", "03", "04" };
private void stiUserData1_GetData(object sender, Stimulsoft.Report.Dictionary.StiUserGetDataEventArgs e)
{
if (e.ColumnName == "Name") e.Data = nameArray[e.Position];
if (e.ColumnName == "Value") e.Data = valueArray[e.Position];
}
}
На скриншоте ниже Вы можете увидеть результат выполнения данного кода: