ReportViewer basic technique for simple report

ReportViewer comes along with Visual Studio 2008 and it is very handy tools if you want to generate report in your website. At least much easier than OpenXml. The best thing is, it support pdf format and do not need to have micro excel in your server(you know what I am saying if you use COM to generate excel). Although its designer is not mature as Crystal report.

There are only three things you  need to create a report. 1. datasource 2. passing parameters 3. hard work.


Database query as datasource is straighy forward using the IDE, I am going to talk about customize datasource in code behind.

Any function that returns a IEnumerable collection could be use as a datasource(If I remeber it correctly). For example :
public static List<yourClass> GetYourClassAsDataSource(Guid param1, int param2) 

You do all calculation you need in that function and then set it as datasource in your page code behind like this.

List<yourClass> l_list = ReportDataAgent.GetYourClassAsDataSource(id,integer);
ReportDataSource rds = new ReportDataSource("DataSourceName", l_list);


ReportParameter yourParam = new ReportParameter("yourParam ", value);
reportviewer.LocalReport.SetParameters(new ReportParameter[] { yourParam });

This is it. I didn’t use any advance features such as drill down report, etc.

Remember to install ReportViewer to your server before it works.

P.S. I am stuck when installing ReportViewer Add-in to VWD express 2008 CHT version.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s