在本节中,将通过向报表的 selectionFormula 值应用 SavedDataSelection 公式来修改 redisplay_Click 方法。
添加按钮单击事件
打开 Web 或 Windows 窗体。
在“视图”菜单上,单击“代码”。
在 redisplay_Click 方法中,删除调用 ConfigureCrystalReports() 方法的代码行。
创建一个 selectionFormula 字符串,在当中字面值与类级别的变量混合。
Dim selectionFormula As String = "{Customer.Last Year's Sales} > " _ & salesAmount _ & " AND Mid({Customer.Customer Name}, 1, 1) " _ & operatorValue _ & "'" _ & customerName _ & "'"string selectionFormula = "{Customer.Last Year's Sales} > " + salesAmount + " AND Mid({Customer.Customer Name}, 1, 1) " + operatorValue + "'" + customerName + "'";将 selectionFormula String 变量赋给 ReportDocument 实例。
customerBySalesNameReport.DataDefinition.SavedDataSelectionFormula = selectionFormulacustomerBySalesNameReport.DataDefinition.SavedDataSelectionFormula = selectionFormula;在下一行上,将 CrystalReportViewer 的 ReportSource 属性绑定到 ReportDocument 实例。
myCrystalReportViewer.ReportSource = customerBySalesNameReportcrystalReportViewer.ReportSource = customerBySalesNameReport;在方法的底部,将 selectionFormula 字符串赋给公式标签 控件的 Text 属性。
formula.Text = selectionFormulaformula.Text = selectionFormula;
现在即可测试应用程序了。