【Stimulsoft Reports Silverlight教程】在代码中使用报表变量
下载Stimulsoft Reports Silverlight最新版本
此示例显示如何使用报表变量并在代码中设置其值。有必要在报表中定义变量,然后可以使用变量名称通过代码设置值。首先,使用变量加载报表:
private void btDesign_Click(object sender, System.Windows.RoutedEventArgs e) { var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("UsingReportVariables.Variables.mrt"); stiReport1.Load(stream); stream.Close(); stream.Dispose(); stream = null; stiReport1.Design(); }
然后,在btPreview_Click事件中,为报表变量分配新值。您可以使用报表变量名称:
private void btPreview_Click(object sender, System.Windows.RoutedEventArgs e) { viewer.Visibility = System.Windows.Visibility.Visible; viewer.Report = null; var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("UsingReportVariables.Variables.mrt"); stiReport1.Load(stream); stream.Close(); stream.Dispose(); stream = null; //Set Variables stiReport1["Name"] = tbName.Text; stiReport1["Surname"] = tbSurname.Text; stiReport1["Email"] = tbEmail.Text; stiReport1["Address"] = tbAddress.Text; stiReport1["Sex"] = rbMale.IsChecked; stiReport1["BirthDay"] = dtBirthDay.DisplayDate; stiReport1.Render(); viewer.Report = stiReport1; }
下面的屏幕截图中,您可以看到示例代码的结果。