Using Object data source in ASP.NET 4 ReportViewer

前端 未结 5 1325
星月不相逢
星月不相逢 2021-01-05 05:23

OK, I think I\'m getting mad here... I thought this should be super simple, but I just can\'t figure out how to do that.

This is what I\'m trying to do: I want to cr

5条回答
  •  别那么骄傲
    2021-01-05 05:37

    I have the same problem and found a way around it. For some reason if you develop a ASP.NET application Microsoft took away add new datasource functionality. The way around is not great but it does work. I use all objects and I use the Enterprise library and I want to use my objects for my reports it only makes sense why they don't enable you to do this. I have no idea why Microsoft would not allow this functionality for web apps.

    But that leaves windows apps it works so what I did was create a separate windows project include my objects that I want to bind to in that project and create the report on the forms project. I then bring that report into my Asp.net web app and call it through code. Here is a few pieces of code that I use to do this. This is in VB but could be converted to C#. I also have a drop down list that selects the report that is needed and a case statement that gets the data.

    Private Sub LoadReport()
    
        Try
            pnlReport.Visible = True
    
            Dim Dal As New DataAccess
            Dim objRptOutputData = New Model.RptClientCollection
            Dim lr As LocalReport = OutputReportViewer.LocalReport
            Dim rds As New ReportDataSource
    
            lr.DataSources.Clear()
    
            OutputReportViewer.Visible = True
            OutputReportViewer.ProcessingMode = ProcessingMode.Local
            OutputReportViewer.LocalReport.EnableHyperlinks = True
    
            Dim SelectedReport As Integer = 0
    
            If Me.ddlReport.SelectedItem.Value IsNot "" Then
                SelectedReport = Me.ddlReport.SelectedItem.Value
            End If
    
      Select Case SelectedReport
          Case ConstantEnum.Reports.ActiveWaitingList
    
            objRptOutputData = Dal.GetRptClientsByStatus(ConstantEnum.Status.ActiveWaitingList)
            lr.ReportPath = "Reporting\Report1.rdlc"
            rds.Name = "dsClient"
            rds.Value = objRptOutputData
            Me.lblCount.Text = "Count: " & objRptOutputData.Count
          Case ConstantEnum.Reports.InactiveWaitingList
            ' This is a small app I have about 15 case statements if it was bigger I would of done this selection a bit different. 
    
            End Select
    
    
    
            lr.DataSources.Add(rds)
            lr.Refresh()
            OutputReportViewer.DataBind()
    
        Catch ex As Exception
            ExceptionUtility.SendError(ex, "Reports", "LoadReport")
        End Try
    End Sub
    

提交回复
热议问题