添加一个应用 SavedDataSelection 公式的事件

在本节中,将通过向报表的 selectionFormula 值应用 SavedDataSelection 公式来修改 redisplay_Click 方法。

添加按钮单击事件

  1. 打开 Web 或 Windows 窗体。

  2. 在“视图”菜单上,单击“代码”。

  3. 在 redisplay_Click 方法中,删除调用 ConfigureCrystalReports() 方法的代码行。

  4. 创建一个 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
    + "'";
    
  5. 将 selectionFormula String 变量赋给 ReportDocument 实例。

    customerBySalesNameReport.DataDefinition.SavedDataSelectionFormula = selectionFormula
    
    customerBySalesNameReport.DataDefinition.SavedDataSelectionFormula = selectionFormula;
    
  6. 在下一行上,将 CrystalReportViewer 的 ReportSource 属性绑定到 ReportDocument 实例。

    myCrystalReportViewer.ReportSource = customerBySalesNameReport
    
    crystalReportViewer.ReportSource = customerBySalesNameReport;
    
  7. 在方法的底部,将 selectionFormula 字符串赋给公式标签 控件的 Text 属性。

    formula.Text = selectionFormula
    
    formula.Text = selectionFormula;
    

现在即可测试应用程序了。