Wednesday, March 28, 2012

ReportViewer control - load parameter

Using Reporting Services in VS.Net 2005 (very much a newbie, though not a
newbie to ASP.Net)
I have a report which runs a Stored Procedure, requiring a parameter -
BudgetID -
In this particular case I just created an ASP.Net page (content page), and I
add a reportViewer control - the wizard picks up my report and creates an
ObjectDataSource, and assigns the report, but nothing is done or asked about
the BudgetID -
I found a reference on the web (in 2004) which showed that I could do
something like this in code:
ReportViewer1.SetQueryParameter("ProductCategory",CategoryDropDown.SelectedV
alue);
So I thought I could do something like this in the page load event - but it
doesn't like the SetqueryParameter method - and searching through all the
properties and methods, I can't seem to find anything like this.
Could someone please shed some light on this for me, please?You need to create an array of
Microsoft.Reporting.WebForms.ReportParameter that holds the parameters
for your report. Then call
ReportViewer1.ServerReport.SetParameters(paramArray). Hope this helps.
Devin
Elmo Watson wrote:
> Using Reporting Services in VS.Net 2005 (very much a newbie, though not a
> newbie to ASP.Net)
> I have a report which runs a Stored Procedure, requiring a parameter -
> BudgetID -
> In this particular case I just created an ASP.Net page (content page), and I
> add a reportViewer control - the wizard picks up my report and creates an
> ObjectDataSource, and assigns the report, but nothing is done or asked about
> the BudgetID -
> I found a reference on the web (in 2004) which showed that I could do
> something like this in code:
> ReportViewer1.SetQueryParameter("ProductCategory",CategoryDropDown.SelectedV
> alue);
> So I thought I could do something like this in the page load event - but it
> doesn't like the SetqueryParameter method - and searching through all the
> properties and methods, I can't seem to find anything like this.
> Could someone please shed some light on this for me, please?|||Please excuse my newbie-ness, but can you explain how to do that?
I've created Arrays from strings before, but I've tried several things, and
it's just not working
"Devin" <dlosee@.granitelp.com> wrote in message
news:1161276979.601948.215490@.i3g2000cwc.googlegroups.com...
> You need to create an array of
> Microsoft.Reporting.WebForms.ReportParameter that holds the parameters
> for your report. Then call
> ReportViewer1.ServerReport.SetParameters(paramArray). Hope this helps.
> Devin
> Elmo Watson wrote:
> > Using Reporting Services in VS.Net 2005 (very much a newbie, though not
a
> > newbie to ASP.Net)
> > I have a report which runs a Stored Procedure, requiring a parameter -
> > BudgetID -
> >
> > In this particular case I just created an ASP.Net page (content page),
and I
> > add a reportViewer control - the wizard picks up my report and creates
an
> > ObjectDataSource, and assigns the report, but nothing is done or asked
about
> > the BudgetID -
> > I found a reference on the web (in 2004) which showed that I could do
> > something like this in code:
> >
ReportViewer1.SetQueryParameter("ProductCategory",CategoryDropDown.SelectedV
> > alue);
> >
> > So I thought I could do something like this in the page load event - but
it
> > doesn't like the SetqueryParameter method - and searching through all
the
> > properties and methods, I can't seem to find anything like this.
> >
> > Could someone please shed some light on this for me, please?
>|||No problem. Basically it's the same as other arrays. Here's what I
have:
Here are the properties for the report viewer control (these can be
changed based on preferences, but here's what I have):
<rsweb:ReportViewer
ID="ReportViewer1"
runat="server"
Height="100%"
Width="100%"
ProcessingMode="Remote"
ShowBackButton="False"
ShowDocumentMapButton="False"
ShowParameterPrompts="False"
ShowPromptAreaButton="False"
BorderColor="Black"
BorderWidth="1px" >
<ServerReport ReportServerUrl="http://SERVER_NAME/ReportServer" />
</rsweb:ReportViewer>
Here is the code for either the OnLoad of the report viewer page or the
OnClick (if you have the params and report viewer on the same form) of
the button for viewing the report:
Dim params As Microsoft.Reporting.WebForms.ReportParameter()
ReDim params(1)
params(0) = New Microsoft.Reporting.WebForms.ReportParameter(
PARAM_1_NAME, PARAM_1_VALUE)
params(1) = New Microsoft.Reporting.WebForms.ReportParameter(
PARAM_2_NAME, PARAM_2_VALUE)
With ReportViewer1.ServerReport
.ReportPath = "/REPORT_FOLDER/REPORT_NAME"
.SetParameters(params)
.Refresh()
End With
There are problems when your report server and website the report
viewer control is on are on 2 separate servers. There's something with
a double hop. I haven't looked too much into this as mine are both on
the same server. If yours are on 2 different servers, you may want to
google the double hop problem (if you are getting security errors).
If you want to get really fancy, you can use inheritance for all of
your parameter forms and then have 1 report viewer form. If that is a
direction you want to take, let me know and I'll post how I did it
(there are many ways, inheritance is just the way I chose).
Elmo Watson wrote:
> Please excuse my newbie-ness, but can you explain how to do that?
> I've created Arrays from strings before, but I've tried several things, and
> it's just not working
>
> "Devin" <dlosee@.granitelp.com> wrote in message
> news:1161276979.601948.215490@.i3g2000cwc.googlegroups.com...
> > You need to create an array of
> > Microsoft.Reporting.WebForms.ReportParameter that holds the parameters
> > for your report. Then call
> > ReportViewer1.ServerReport.SetParameters(paramArray). Hope this helps.
> >
> > Devin
> >
> > Elmo Watson wrote:
> > > Using Reporting Services in VS.Net 2005 (very much a newbie, though not
> a
> > > newbie to ASP.Net)
> > > I have a report which runs a Stored Procedure, requiring a parameter -
> > > BudgetID -
> > >
> > > In this particular case I just created an ASP.Net page (content page),
> and I
> > > add a reportViewer control - the wizard picks up my report and creates
> an
> > > ObjectDataSource, and assigns the report, but nothing is done or asked
> about
> > > the BudgetID -
> > > I found a reference on the web (in 2004) which showed that I could do
> > > something like this in code:
> > >
> ReportViewer1.SetQueryParameter("ProductCategory",CategoryDropDown.SelectedV
> > > alue);
> > >
> > > So I thought I could do something like this in the page load event - but
> it
> > > doesn't like the SetqueryParameter method - and searching through all
> the
> > > properties and methods, I can't seem to find anything like this.
> > >
> > > Could someone please shed some light on this for me, please?
> >

No comments:

Post a Comment