Home   |  Articles   |  Resources   |  Humor   |  Feedback       

  Login   Register 

Ads Via DevMavens


Reporting Services and the Report Viewer component - Part II

Posted by on Saturday, June 19, 2004

This article demonstrates how to embed the ReportViewer component in an ASP.Net web page, input parameters in your aspx page and pass them to Reporting Services

Since I posted the initial article on Reporting Services and the Report Viewer component, we have had a steady slew of questions and emails about it. Rather then answer each one of these questions individually, I’ve decided to post an example on how to use this component from a web application and hopefully answer the entire gamut of questions.

Many of you have faced the situation where you need to build a custom UI for your report. It could be to enable you to do user specific validation for input parameters, or to match the look and feel of you current web application, or to support multi-select parameters. Whatever the reason, this seems to be a common requirement.

In this example, I am going to create a new web project – RsFromAWebApp and embed the Product Line Sales Report, which is a part of the SampleReports project that is including with Reporting Services.  The input parameters for this report are going to be entered on the Web Form via user controls, and not using Reporting Services.

The Product Lines Sales Report has four input parameters, Product Category, Product Sub Category, Start Date and End Date. The first thing I want to do is create my own set of user controls in my Web form.  So lets take a look at the web form :

    <form id="Form1" method="post" runat="server">
      <table height="95%" width="95%">
        <tr id="Toolbar" height="100" bgcolor=#ccccff>
          <td>Category<asp:dropdownlist id="CategoryDropDown"
runat="server" Width="120px"
AutoPostBack="True"></asp:dropdownlist></td>
          <td>Sub Category<asp:dropdownlist id="SubCategoryDropDown"
runat="server" Width="120px"></asp:dropdownlist></td>
          <td>Start Date<asp:textbox id="StartDate" runat="server"
Width="110px"></asp:textbox></td>
          <td>End Date<asp:textbox id="EndDate" runat="server"
Width="110px"></asp:textbox></td>
          <td><asp:button id="Button1" width="30px" runat="server"
Text="Go"></asp:button></td>
        </tr>
        <tr id=Main>
          <td colspan="5"><cc1:ReportViewer id="ReportViewer1"
runat="server" width="100%" height="95%" ></cc1:ReportViewer></td>
        </tr>
      </table>

Having created the form to look exactly as we need, and validated it the next step is to pass the values in the above user controls to the report viewer component. We need to find the name of the parameters expected by the Product Line Sales Report. To do this click on Report --> Report Parameters and we find that the Parameter names are ProductCategory, ProductSubCategory, StartDate and EndDate. We now have all the information we need to proceed. As in the previous article, we now need to specify the ServerURL and the Report name to the Report Viewer component.

 

ReportViewer1.ServerUrl=@"http://localhost/ReportServer";
ReportViewer1.ReportPath=@"/SampleReports/Product Line Sales";

To pass the parameters to the report, we need to use the SetQueryParameter method that we added to the ReportViewer component in the last article.

ReportViewer1.SetQueryParameter("ProductCategory",CategoryDropDown.SelectedValue);
ReportViewer1.SetQueryParameter("ProductSubCategory",SubCategoryDropDown.SelectedValue);
ReportViewer1.SetQueryParameter("StartDate",StartDate.Text);
ReportViewer1.SetQueryParameter("EndDate",EndDate.Text);
Our next step is to hide the parameters part of the toolbar created in the Report. Since our web page now accepts user inputs, we don’t need Reporting Services to do this.
ReportViewer1.Parameters=Microsoft.Samples.ReportingServices.ReportViewer.multiState.False;

If you want to hide the rest of the toolbar as well (the area from where you can export to another format), set the Toolbar to false.

ReportViewer1.Toolbar=Microsoft.Samples.ReportingServices.ReportViewer.multiState.False;

 Compile your project and this is what your page should look like

Login to download code

\

 

by Poonam Lall


Comments:

parameters not in webform?
By mgonzales3 on 6/22/2004
i compiled the project and for some reason my dropdown lists are not being populated. any idea?

Question about how the page opens
By neilgould on 7/16/2004
I went through your articles and they were great. I have this one working but when I first open the page, the report is fully rendered using the parameters in the report design. Also the toolbar is displayed. Once I enter the parameters on the web page and GO, the right data is displayed and the toolbar is off. When I select another catagory, the report is fully rendered again. Anyway around this? Remove the default parameters from the report definition?
Thanks,
Neil

Put it on the Internet
By JasmineRose on 7/22/2004
I have followed this article and created a .net application .How can we publish this on the internet.It works internally.

C# code with Reporting Services
By martlin on 7/27/2004
Hi Sir,

I downloaded your C# source code for the sample reporting services. I followed your code modification but I got c:\inetpub\wwwroot\webapplication1\reportviewer.cs(81,57): error CS0234: The type or namespace name 'Design' does not exist in the class or namespace 'Microsoft.Samples.ReportingServices' (are you missing an assembly reference?)
c:\inetpub\wwwroot\webapplication1\reportviewer.cs(81,57): error CS0234: The type or namespace name 'Design' does not exist in the class or namespace 'Microsoft.Samples.ReportingServices' (are you missing an assembly reference?)

Could you please let me know why?

Please send e-mail to martlin8@hotmail.com. I would highly appreciate your help.

Thanks,

Martin

Error in parameters using reportviewer whit string too large
By aap7401 on 7/27/2004
Error in parameters using reportviewer whit string too large.
no display the page and I have verified that fails with very great chains

similar control for windows form
By sscf on 8/3/2004
does anybody knows if its possible to port the ReportViewer componente to windows form?? i´ve already have success with the reportviewer for asp.net

ReportViewer DLL
By rwiethorn on 8/3/2004
I'm trying to make my own WEb app, practicing using the ReportViewer control that is supplied in the Sample.

I ran the sample: ReportViewer, and found the 'ReportViewer.dll'

I created a new ASP.Net app in VB., and installed it according to the documentation in the Books On Line "ms-help://MS.RSBOL80.1033/RSAMPLES/htm/rss_sampleapps_v1_7944.htm"

I assigned a value for the Server (http://localhost/reportserver), and a value for the report (/SampleReports/Company Sales),per the instructions on: ms-help://MS.RSBOL80.1033/RSAMPLES/htm/rss_sampleapps_v1_7944.htm, from Books on line.

I release the viewer would be 'static' for a single report but I just starting out.

I got an error: An attempt has been made to use a rendering extension that is not registered for this report server. (rsRenderingExtensionNotFound)

I searched the BOL and MSDN site, but no results. Anyone have any suggestions to get started using the ReportViewer control?

Thanks,
rwiethorn

Print report
By istavnit on 8/20/2004
Is there any way to automatically print report when user clicks a button in webform that contains reportviewer?(without showing Reporting Services toolbar)

Thank you

Reporting Services and the Report Viewer component - Part II
By jwatsonzia on 8/30/2004
Hi! I am using the Report Viewer in a VB Web application. When I view the web application, the report viewer automatically jumps to the top of the page. I have the control actually places down the page after the criteria selection for the parameters. Do you know I can control the placement of the report? Your version doesn't appear to have this problem. Is it a setting? Thank you for the help!

Location Problem
By jwatsonzia on 9/3/2004
Hi! I have the Report viewer working. I can even pass in my parameters. However, the report always showes up at the top of my web form no matter where I place it or how I change any of the settings. It is like it is ignoring the actual location. Any ideas? I assume I am just missing a setting somewhere. Help! Thank you!

SetQueryParameter
By jwatsonzia on 9/13/2004
Hi! I am using this method to call my reports. I have multiple reports that I am passing. I want to modify the SetQueryParameter to check if the Parameter exists in the report first, can I do this? If so, how? I really appreciate any help you can give me. Thank you!

Report Viewer Not Picking Up Parameters
By smolinsd on 9/16/2004
I can't see to have my report pick the parameters that I am passing to it. I downloaded your code and followed your examples but can't seem to get it to work. Is there anything special you did in reporting services or maybe something else. Thank you for you time.

Drill down not working in web form
By kolansameera on 9/16/2004
Hi,

I have used the reportviewer to show the report in my web-form (as is explained here) Every thing wored out fine, except that my report has drill downs on a group and the drill downs dont seem to work. When I open this report with report manager the drill down works like a champ.

I have seen the other postings with similar problem on MSDN newsgroup, but was of not any help.

I would appreciate any solution for this problem.

Thanks,
Sam

Drill down not working in browser
By kolansameera on 9/20/2004
Hi,

I have followed the process explained in this article and used the report viewer dll in a web form to show the report. This report has a drill down on the group and the details are shown when the toggle/drill down is clicked. The problem here is, the drill down does not work. With report manager the toggle (+/-) works like a champ. And also there is one more weird behavior, when the drill down is made to open in a new window, or whe nthe report is exported to PDF, the drill down works fine (until the report is refreshed). Is this to do some with the sessions?

I have found similar postings by others on microsoft newsgroups, but couldnt find solution to this problem.

I would appreciate if you could help me with this.

Thanks,
Sam

Report is asking for credentials
By sreekumar on 9/28/2004
Hi

I am having a problem while viewing the report thru report viewer. It works properly with the localhost. But when i gave my Ip address instead of localhost it is asking for N/w username and password. How can i remove these credentials because i am using this on a web page.

Thanks in advance

Drillthrough/ Drilldown
By rey on 10/6/2004
is it possible to set the drillthrough page to be displayed inside the report viewer.


Thanks
Rey

Collapsible items in embedded report
By KATO on 10/7/2004
Hello,

I embedded a report in my web app, but the collapsible items contained in the report do not work.

Any ideas will be greatly appreciated.

Problem with ReportView
By ? on 10/27/2004
Hi,

I have found both articles about reporting services very interesting. In fact I have used most of it in some reports I have recently created. However I have found a small problem that I cannot fix and I assume more people will have had the same one.
My application is using the ReportViewer to display the reports but one of the reports links to another report. The first report is displayed correctly (within the IFRAME) but the second report just opens in a new IE window. I read somewhere that I should set the rc:LinkTarget parameter to the name of my IFRAME but to be honest, I do not know the name of the IFRAME because the IFRAME is generated when I drag and drop the component and does not seem to have a name.
Any ideas would be very helpful.
Thanks in advance
Alonso

Hide Report Manager Navigation
By CSnerd on 10/30/2004
When I point to my reports server, essentially the reports manager web page is displayed in the control if I just want the toolbar and report to be displayed and nothing else what do I need to do

vb version
By xyz_999 on 10/31/2004
Is there a VB version of this code?

security
By ColinR on 1/4/2005
Thanks, this works localhost, but what is required to access reports from another pc on the network.

I get as far as the reports page showing reporting folders, but not the actual report if I navigate to the report I am prompted for security but there are obviously no params passed.



Good article, but still a question ...
By cedtat on 1/6/2005
This article (with the previous) give me answers ... but i have still a question which is very tricky. There is a limitation for the querystring parameters, apparently the reportviewer component use the querystring to pass the parameters so it is bugging when there is to much parameters ...

before finding this component, i was trying to find a solution to pass this parameters in a POST method but wasn't able to do it properly ...

Do you have an idea on how to pass the parameters selected on a custom form to reporting services without this limitation ? and of course i want to use the reportviewer component or at least, the reportviewer on the server ...

How to make DrillThrough reports work
By raviloko on 2/25/2005
Hello Poonam,

I am using a reportviewer Control in one of my asp.net web app. and my reports have a lot of drillthrough links to other reports.
But when I click the drillthrouh it opens in a new page. I am trying to confine it to the control on the current page but so far not successful. Do you know how to use the rc:ReplacementRoot functionality ?

Thanks
Ravi

Copyright 2004 OdeToCode.com 


The Blogs
Subscribe to the OdeToCode blogs for the latest news, downloads, new articles, and quirky commentary.
New Articles
Databinding in Silverlight
This article will cover data binding features in Silverlight, including binding expressions, validation, converters, and binding modes.

The Standard LINQ Operators
This article will cover the standard LINQ operators provided by LINQ for filtering, grouping, joining, converting, projecting, and more.

C# 3.0 and LINQ
C# 3.0 introduced a number of new features for LINQ. In this article we'll examine the new features like extension methods, lambda expressions, anonymous types, and more.

Most Popular Articles
Table Variables In T-SQL
Table variables allow you to store a resultset in SQL Server without the overhead of declaring and cleaning up a temporary table. In this article, we will highlight the features and advantages of the table variable data type.

ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps
MasterPages are a great addition to the ASP.NET 2.0 feature set, but are not without their quirks. This article will highlight the common problems developers face with master pages, and provide tips and tricks to use master pages to their fullest potential.

AppSettings In web.config
In this article we will review a couple of pratices to keep your runtime configuration information flexible.

Contribute Code
Privacy
Consultancy