以编程方式过滤或设置参数报告(rdlc)

时间:2014-11-22 15:28:13

标签: vb.net reportviewer rdlc

我在VB2010上创建了一个报告(不是向导),我以编程方式使用数据集设置了数据源,我想在报告中添加一个过滤选项

Dataset

Tablix Filter Properties

原始代码: 此代码显示所有没有过滤的数据

Dim rptDataSource As ReportDataSource


            With rptReportViewer.LocalReport
                .ReportPath = "Reports\" & strReport & ".rdlc"
                .DataSources.Clear()
            End With

            Select Case strReport
                Case "rptProducts"
                    Dim ds As New dsProducts
                    Dim da As New dsProductsTableAdapters.ProductsTableAdapter

                    da.Fill(ds.Products)

                    '//use the same name as defined in the report Data Source Definition
                    rptDataSource = New ReportDataSource("ProductsDataSet", ds.Tables("Products"))

            End Select

            rptReportViewer.LocalReport.DataSources.Add(rptDataSource)
            rptReportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
            rptReportViewer.ZoomMode = ZoomMode.Percent
            rptReportViewer.RefreshReport()

我做了一些谷歌搜索,我插入了一些代码

修改后的代码

        Dim rptDataSource As ReportDataSource
        **'this code inserted**
        Dim FilterBrand As New ReportParameter("FilterBrand", txtfilter.Text)


            With rptReportViewer.LocalReport
                .ReportPath = "Reports\" & strReport & ".rdlc"
                .DataSources.Clear()
            End With

            Select Case strReport
                Case "rptProducts"
                    Dim ds As New dsProducts
                    Dim da As New dsProductsTableAdapters.ProductsTableAdapter

                    da.Fill(ds.Products)

                    '//use the same name as defined in the report Data Source Definition
                    rptDataSource = New ReportDataSource("ProductsDataSet", ds.Tables("Products"))

            End Select

            rptReportViewer.LocalReport.DataSources.Add(rptDataSource)
            **'this code inserted**
             rptReportViewer.LocalReport.SetParameters(New ReportParameter() {FilterBrand})
rptReportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
            rptReportViewer.ZoomMode = ZoomMode.Percent
            rptReportViewer.RefreshReport()

报告说在报告处理期间发生错误,有什么问题,如何以编程方式设置过滤?

由于

2 个答案:

答案 0 :(得分:0)

您必须在过滤器值中使用表达式:

=Parameters!FilterBrand.Value

答案 1 :(得分:0)

如上一个答案中所建议,您可以按照以下示例操作: enter image description here

enter image description here