This example shows how to use the Report Variables in code. It is necessary to define variables in the report, then the values can be set through code using the variable name. You read more about variables in our
documentation.
First, load the report with variables:
private void ButtonShow_Click(object sender, RoutedEventArgs e)
{
var report = new StiReport();
report.Load(@"Reports\Variables.mrt");
// Required to prepare the in compilation mode
report.Compile();
...
Then, assign new values to report variables. You can use the report variable name for this:
...
// Set Variables
report["Name"] = TextBoxName.Text;
report["Surname"] = TextBoxSurname.Text;
report["Email"] = TextBoxEmail.Text;
report["Address"] = TextBoxAddress.Text;
report["Sex"] = RadioButtonMale.IsChecked.GetValueOrDefault();
...
In the end, show the report in the WPF viewer:
...
report.ShowWithWpf();
}
Auf dem Screenshot unten Sie können das Ergebnis des Beispiel-Codes ansehen: