Generate columns dynamically in RDLC

后端 未结 2 1787
花落未央
花落未央 2020-12-18 09:48

I am trying to generate a RDLC report in ASP.NET where the columns of my Dataset will be dynamic and determined only at run time.

I have a made a function that retur

2条回答
  •  情歌与酒
    2020-12-18 10:24

    I am not sure your question is framed too elegantly. It is not possible to create a truly ad-hoc report. The work around is this. - Create the rdlc file - Create a dataset xsd file in the format you would get your data from. You will have to do this manually and each column should match your eventual output - Bind the rdlc file to this dataset datasource - Design your report

    Now in the query generating part, you have to bind the dynamic data to the rdlc like this

                    Dim repDS As New Microsoft.Reporting.WebForms.ReportDataSource
                    repDS.Value = dT
                    repDS.Name = "dsConsolReq_dt1" 'hard coded here, but you should get it dynamically perhaps from the querystring or the db
    
                    RV1.LocalReport.DataSources.Clear()
                    RV1.LocalReport.DataSources.Add(repDS)
                    RV1.LocalReport.ReportPath = "Reports\rep_itemr1.rdlc" 'same again, use dynamic values
                    RV1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local
                    RV1.LocalReport.Refresh()

    The key here is the NAME of the report data source. It should exactly match the dummy dataset/datatable that you created for designing your report

提交回复
热议问题