RDLC report integration in ASP.NET Webforms using Object Data Source – SSRS

Standard

So in order to use SSRS reports in asp.net webforms application, following code comments should be taken care of:

1. Processing mode should be local in case of SSRS report
2. Object data source should be bind to class containing prototype of data access layer method
3. Empty data source object before each execution
4. set report parameter [if any]
5. set object data source parameter [if any]
6. set path of SSRS report
7. set method of object data source for processing of report
8. object data source id should be same as defined in client side / designer page [.aspx]
9. use same report data source which is used in SSRS report

Its done 🙂

Client Side:

<rsweb:ReportViewer ShowWaitControlCancelLink=”false” ID=”ReportViewer”
runat=”server” Width=”100%” ProcessingMode=”Local”>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID=”objDataSource” runat=”server”></asp:ObjectDataSource>

 

Server Side:

protected void btnShowReport_Click(object sender, EventArgs e)
{
ReportViewer.LocalReport.DataSources.Clear();

//Processing mode should be local in case of SSRS report
ReportViewer.ProcessingMode = ProcessingMode.Local;

ReportViewer.Attributes.Add(“style”, “margin-bottom: 30px;”);
ReportViewer.ShowParameterPrompts = false;
ReportParameter[] reportParameterList = new ReportParameter[2];

//Object data source should be bind to class containing prototype of data access layer method
objDataSource.TypeName = “BusinessLogic.SampleBusinnessMethods”;
objDataSource.SelectParameters.Clear();

//Empty data source object before each execution
ReportViewer.LocalReport.DataSources.Clear();

//set report parameter [if any]
reportParameterList[0] = new ReportParameter(“id1”, 2, false);
reportParameterList[1] = new ReportParameter(“id2”, 3, false);

//set object data source parameter [if any]
objDataSource.SelectParameters.Add(“id1”, TypeCode.Int32, “2”);
objDataSource.SelectParameters.Add(“id2”, TypeCode.Int32, “3”);

//set path of SSRS report
agentMonitorReportViewer.LocalReport.ReportPath = Server.MapPath(“Report.rdlc”);

//set method of object data source for processing of report
objDataSource.SelectMethod = “SelectMethodName”;

var rptDataSource = new ReportDataSource();

//object data source id should be same as defined in client side / designer page [.aspx]
rptDataSource.DataSourceId = “objDataSource”;

//use same report data source which is used in SSRS report
rptDataSource.Name = “ReportDataSet”;
ReportViewer.LocalReport.DataSources.Add(rptDataSource);
ReportViewer.LocalReport.SetParameters(reportParameterList);
ReportViewer.DataBind();
ReportViewer.LocalReport.Refresh();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s