Following is code done by me to add report viewer control dynamically to display reports
ReportViewer ReportViewer1 = new ReportViewer();
if (ddlListofReports.SelectedValue != "11")
{
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.ID = "ReportViewer1";
ReportViewer1.Font.Bold = false;
ReportViewer1.Font.Name = "Arial";
ReportViewer1.ShowBackButton = false;
ReportViewer1.SizeToReportContent = true;
ReportViewer1.BackColor = System.Drawing.Color.WhiteSmoke;
ReportViewer1.LocalReport.DataSources.Clear();
}
#endregion reportviewer setting
#region CampaignProgressReport
if (ddlListofReports.SelectedValue == "0")
{
_reportID = "CampaignProgressReport";
List<SnapshotReport> List = new SnapshotReport().GetCustomersForCountry(this.DropDownList1.SelectedValue, this.DropDownList2.SelectedValue, dcfromdate.Text);
ReportViewer1.LocalReport.ReportPath = "Admin\\ReportDesigns\\" + _reportID + ".rdlc";
if (List != null)
{
if (List.Count > 0)
{
ReportParameter ServiceName = new ReportParameter("ServiceName", this.DropDownList1.SelectedItem.Text);
ReportParameter[] p = { ServiceName };
ReportViewer1.LocalReport.SetParameters(p);
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("SnapshotReport1", List));
isnull = false;
}
}
}
#endregion CampaignProgressReport
divRptView.Controls.Add(ReportViewer1);
ReportViewer1.Height = 290 + (25 * 10);
ReportViewer1.Width = Unit.Percentage(91);
ReportViewer1.ShowRefreshButton = false;
ReportViewer1.Visible = true;
ReportViewer1.ShowPrintButton = true;
ReportViewer1.SizeToReportContent = true;
ReportViewer1.LocalReport.Refresh();
if you have any query feel free to contact