How to show dynamically generated datatable in reportviewer in asp.net?

∥☆過路亽.° 提交于 2019-12-04 06:44:24

问题


I've a ReportViewer(.rdlc) in my app. I want to show a datatable, which is generated dynamically from codebehind, in Reportviewer in Table object.

How to do this? dataset has to be sent to report through codebehind.

I Have My Code Behind file

  DataTable dt = Session["ReportOnUser"] as DataTable;
  if (dt.Rows.Count > 0)
  {
      ReportDataSource rds = new ReportDataSource("ReportOnUser", dt);
      ReportViewer1.LocalReport.DataSources.Clear();
      ReportViewer1.LocalReport.DataSources.Add(rds);
      ReportViewer1.LocalReport.Refresh();
  }

aspx file:

 <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="800px">
    <LocalReport ReportPath="Reports\Report1.rdlc">
        <DataSources>
            <rsweb:ReportDataSource DataSourceId="ReportOnUser" Name="ReportOnUser" />
        </DataSources>
    </LocalReport>
</rsweb:ReportViewer>

I have adde an rdlc file with No design or xsd file Report1.rdlc.


回答1:


The Code above is working perfectly. the only issue was 'Microsoft.ReportViewer.WebForms' dll added was of different version.



来源:https://stackoverflow.com/questions/23751478/how-to-show-dynamically-generated-datatable-in-reportviewer-in-asp-net

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