This is not an easy task! Here are six steps for you.
1. Web.config
To get started, open your web.config and add the following to the <system.web> section
<httpHandlers> <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false" /> </httpHandlers>
and then in the <compilation> add the following:
<buildProviders> <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </buildProviders>
and then in the <system.webServer> add the following:
<handlers> <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </handlers>
and add a link to Microsoft.ReportViewer.Common.dll and Microsoft.ReportViewer.WebForms.dll (version 10.0.0.0).
2. Global.asax
Open the Global.asax.cs function and in the RegisterRoutes () function add the following:
While you are doing this, create a new folder named "ReportViewer" in your asp.net application.
3. XSD dataset
Create a new XSD file in the ROOT of your project folder (yes, it must be the root!).
Right click on your project, click "Add New DataSet". It must be empty.
Right-click on it and select "Add", "Table" ...
Select the database connection string. Save it in the application configuration. Use an existing stored procedure. Fill the data set using the SELECT query. Give the dataset a meaningful name.
4. Create an RDLC report
Create a new RDLC report file (you will need BI tools for this) and go to "Add Dataset". Select a new dataset. Create a report. Pay attention to the name of the dataset. (For example, "DataSet1", be sure to change it later to something more useful.)
5. Customize the ASPX page
Create a new ASP.NET web form, yes, a web page called ShowReport.aspx. HTML should have the following:
<body> <form id="form1" runat="server" > <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <rsweb:ReportViewer ID="ReportViewer1" SizeToReportContent="False" Width="820px" Height="820px" runat="server" ShowRefreshButton="false" AsyncRendering="false" DocumentMapCollapsed="True" PageCountMode="Actual" PromptAreaCollapsed="True"></rsweb:ReportViewer> </form> </body>
6. Codebehind
Inside codebehind for your reports.aspx.cs do the following:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DataSet dataset = GetPopulatedDatasetFromDB()
Visit the page:
http: //localhost/MyApp/ReportViewer/ShowReport.aspx
Voila!