How to show dynamically generated datatable in rep

2019-03-05 07:05发布

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条回答
可以哭但决不认输i
2楼-- · 2019-03-05 07:53

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

查看更多
登录 后发表回答