RDLC之報表參數(報表鉆取)

標題:RDLC之報表參數(報表鉆取)

作者:huangtao

時間:2008719

目的:報表跳轉,參數傳遞

內容:oracledeptemp為例,點擊empdeptno,顯示dept的資訊

步驟:

1)      新建一個web項目

2)      添加報表,Emp.rdlc,Dept.rdlc

3)      添加資料集

4)      設計報表

5)      設定參數,emp.rdlc傳遞參數deptno,dept.rdlc接受參數。所以兩個報表的參數要一致。

6)      設定emp.rdlc的參數。右击单元格à属性:

 

 

7)      按照下图设定以下参数就行了,emp的参数就设好了。

 

 

8)      dept.rdlc设定参数 “报表”菜单à“报表参数”:

 

 

9)      设定参数名称: 


 

报表设计好了,接下来就是将它嵌入到aspx中。

1)      在页面上拖放一个ReportView控件

为控件指定报表路径和资料集(这里使用自定义资料集)
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then

            Bind()

        End If

    End Sub
    Sub Bind()

        Me.ReportViewer1.ShowToolBar = True

        '启用超链接

        Me.ReportViewer1.LocalReport.EnableHyperlinks = True

        Dim _strSql As String = "SELECT EMPNO,ENAME,JOB,DEPTNO FROM EMP"

        Dim dsEmp As New DataSet

        Dim DB As New DataAccess.DatabaseHelper

        dsEmp = DB.ExecuteDataSet(_strSql)

        Me.ReportViewer1.LocalReport.ReportPath = "Emp.rdlc"

        Me.ReportViewer1.LocalReport.DataSources.Clear()

        Me.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("Myds", dsEmp.Tables(0)))

        dsEmp.Dispose()

        DB = Nothing

    End Sub

 

2)     到此只是报表可以显示数据,但是钻取功能还没有实现。需要实现Drillthrough 事件
    Protected Sub ReportViewer1_Drillthrough(ByVal sender As Object, ByVal e As Microsoft.Reporting.WebForms.DrillthroughEventArgs) Handles ReportViewer1.Drillthrough

        Dim _deptno As String = Nothing

        Dim _strSql As String = Nothing

        Dim _dsDept As New DataSet

        Dim DB As New DataAccess.DatabaseHelper

        '獲取參數

        Dim lp As Report

        lp = CType(e.Report, Report)

        _deptno = lp.GetParameters()("deptno").Values(0).Trim()

        _strSql = "SELECT DEPTNO,DNAME,LOC FROM DEPT WHERE DEPTNO=" & _deptno

        _dsDept = DB.ExecuteDataSet(_strSql)

        Dim localReport = e.Report

        localReport.DataSources.Add(New _

        ReportDataSource("MyDept", _dsDept.Tables(0)))

        _dsDept.Dispose()

        DB = Nothing
    End Sub

ReportView控件用于在web页面中显示报表,有点类似在IFrame中显示网页。

报表钻取,鼠标触发钻取事件后,另一个Report会在同一个ReportView控件中显示,不会像超链接那样打开另外一个窗口。

报表共有3个超链接动作,除了跳到报表,还有跳到书签,跳到URL

posted @ 2008-07-19 18:55  yellowwood  阅读(1024)  评论(0编辑  收藏  举报
Never Give UP