Using Object data source in ASP.NET 4 ReportViewer

只谈情不闲聊 提交于 2019-11-30 19:30:15

did you follow this tutorial?
everything you must do is:

  • define your DTO classes or generate it using EF4 (for example)
  • define your business classes with some methods (like GetAll...)
  • build your solution (that's important)

now from your report designer you can choose methods from business classes as dataset and drag and drop field from the DTO classes
when you choose that report to display in the reportviewer, the datasource object will be added for you

I found this blog very helpful.
When you create a new datasource for your rdlc, in the Dataset Properties dialog:
1) In the Data source drop down, select the namespace that contains the class which contains the public method (see #2).
2) In the Available datasets drop down, select the public method that returns an IQueryable of your business objects.

Is your business object class marked as public? I've seen in a video that it must be public.

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

Have you seen this earlier version? Is this what you need:

http://msdn.microsoft.com/en-us/library/ms252073(v=VS.80).aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!