Hi,
I am using the Report Viewer Control to display the Reports. My query is generated dynamically so that output the query is a datatable. My application gives the user the flexibility to select the tables & the table-fields on which he wants to run the report. So I cannot have a fixed report file as I do not know what will the user select.
I tried adding the result datatable as the datasource for the report dynamically.
protected void RunReport_Click(object sender, EventArgs e){string constg ="server=localhost;Database=techapp;user id=sa;password=admin;";SqlConnection con =new SqlConnection(constg);//query is the query string that is generated at runtimeSqlDataAdapter da =new SqlDataAdapter(query,con);DataSet ds =new DataSet();da.Fill(ds,"ReportDataTable"); con.Close();ViewReport(ds.Tables["ReportDataTable"]);}protected void ViewReport(DataTable dt){ ReportViewer1.ProcessingMode = ProcessingMode.Local; ReportDataSource rd =new ReportDataSource(); rd.Name ="ReportData_Data"; rd.Value = dt; ReportViewer1.LocalReport.DataSources.Add(rd); ReportViewer1.DataBind();}
My problem is that the entire code gets executed properly without any exception but the report is not displayed. I checked the ReportDataSource & it shows the proper value. In all the samples that I went through, I found that they have mentioned a report file. I don't know if this is the cause of the problem, but if it is then In mycase how can I create a report design file if I wouldn't know what to add in that file at design time.
I do not have an expertise in this. can anyone please guide me through the right way & let me know what is it that I'm not doing correct?
I guess its the problem with height of report
Check whether you have set the height of report as 100%. Change that to some fixed size let say 800px.
Let me know if you need any further help
|||Hi Ashok,
I tried adjusting the height of the report viewer . This is the changed code but it still doesn't show any thing.
ReportViewer1.ProcessingMode = ProcessingMode.Local; ReportViewer1.Height = Unit.Pixel(500); ReportDataSource rd =new ReportDataSource(); rd.Name ="ReportData_Data"; rd.Value = ds.Tables["ReportDataTable"]; ReportViewer1.LocalReport.DataSources.Add(rd); ReportViewer1.DataBind();
Could the problem be the absence of a report design file ie an rdlc file. I downloaded a sample code from net where the report file is created dynamically & it seemed to work this way.
Is a report design file by default required for the report viewer control to display the report? What is the complexity involved in creating such design files on your own?? Can you shed some light on these points ?
Thanks
No comments:
Post a Comment