There will be cases in which we need to load a local report on ReportViewer control. The below code will help to do the same.
//Declare ReportViewer object
public Microsoft.Reporting.WebForms.ReportViewer reportViewer1;
reportViewer1.ProcessingMode = ProcessingMode.Local;
reportViewer1.LocalReport.ReportPath = path;
reportViewer1.LocalReport.
ExecuteReportInCurrentAppDomain(
System.Reflection.Assembly.GetExecutingAssembly().
Evidence);
// The application is responsible for collecting
// parameters
ReportParameterInfoCollection parameterInfo =
reportViewer1.LocalReport.GetParameters();
if (parameterInfo.Count > 0)
{
List<ReportParameter> param = new List<ReportParameter>();
ReportParameter yearParam = new ReportParameter("Year", “2009”);
param.Add(yearParam);
// Add report data sources
ReportDataSource rds = new ReportDataSource("ds", dataSourceObject);
reportViewer1.LocalReport.DataSources.Add(rds);
// Add report parameters
reportViewer1.LocalReport.SetParameters(param);
}
reportViewer1.LocalReport.Refresh();
Hope this helps :)
If you have any query, please feel free to ping me.
No comments:
Post a Comment