Quantcast
Channel: Getting ReportViewer client parameters at runtime
Viewing all 20 articles
Browse latest View live

Re: Getting ReportViewer client parameters at runtime

$
0
0

Thanks for the help.  I have it running very well right now.  Here's what I had to do:

1 - I get the current defaults from the ServerReport using the GetParameters method.  This returns the default parameters for the ServerReport

2 - I have some parameter limits and defaults for my application that I need to apply to various report parameters.  We're storing these in a local SQL Server database using the reportpath to uniquely identify the report.  I put those in generic List of Report Parameters.

3 - I also walk the control tree and extract everything in there that looks like a report parameter into a generic List of ReportParameter (these are what my user modified)

Finally, I use a method to come up with a "final" set of parameters to use for this render and then apply those to the ServerReport using SetParameters().  The method takes the default parameters and then adjusts values based on the parameter limits and defaults and then applies the client parameters last.  I use the PromptUser and Visibility attributes to determine if I should even bother with the client-manipulated parameter.  At the bottom of the method I simply apply the resulting List using SetParameters.

 I do all of this in the PreRenderEventHandler.  The reflection through the control tree (see my c# code above) is not overly costly, although there is an impact.  Still, the whole thing works great now.  I'm also storing that collection of parameters and other information about the ServerReport into a Report object that I create and store in a stack so I can allow my user to step back and forward through the reports they've rendered and have them show up using the parameters they specified originally.  I've even created my own breadcrumb trail so I can show drilldowns, etc. 

Thanks for the help everyone!

Now on the the next thing - disabling the contextmenu for the Reserved.ReportViewer.  I can get the rest of the screen to ignore righ-clicks, but the ReportViewer frame doesn't seem to want to allow me to disable that.  Even a walk through the frames collection doesn't seem to be getting the results I want - GRRRR!!!!


Re: Getting ReportViewer client parameters at runtime

$
0
0

ERDoll

I cannot seem to do the following:

 1)  I have a report that uses the ASP.NET 2.0 Report Viewer against a RS2005 report that has parameters.  Some have default values.  One is a text box.  Others are drop-down lists.
2)  I have ShowParameterPrompts = true and am presented the parameter area upon first visit to the page.
3)  I fill in the parameters on the web browser page and click the View Report button
4)  Now, on the server side, I want to examine the parameter values (in the Page_Load event).  When I do a GetParameters on the ServerReport of the ReportViewer, I receive back a collection of the default parameters values, not the values that I just submitted. 

How do I see the parameter values submitted by the client?

Other information I found while investigating this:

1)  If I click on the View Report button again (and again), GetParameters always return the previous set of parameters, not the current values that the client submitted.
2)  If I look at the Request.Forms collections I can see values for controls that have been generated by the ReportViewer control in the parameters area - where the values are different when the client submitts new parameters.
3)  If I do a GetParameters in the pages Page_PreRender event, I see the same behavior.
4)  I can do a walk of the control tree inside the report view control instance and see the various controls created for the parameters area.  Those controls have the Request.Form values in them.
5)  The Report Viewer, load, report refresh and prerender events don't seem to be much help either.

I could hack a solution using the control tree or the Request.Form values, but that's rather inelegant and relies on Micrsoft not changing the ReportViewer control's behavior. 

 Any explanations of what is happening here would be appreciated.  Thanks,

ER Doll

 

Hi, I implemented more complex task with report parameters. I don't use ShowParameterPrompts = true. I will put some examples on my site soon.

Alexei Cioina.

http://www.californiadreamhomesandland.com

 

Re: Getting ReportViewer client parameters at runtime

$
0
0

okay - thanks.  I completed the conversion and it seems to be working okay although I never could get the Type to work properly so just ended up handling it another way.  If anyone would like the code, I'll put it at the end. 

 I do have one more issue though - the SetParameters doesn't seem to be actually setting the parameters for the report.  I'm doing it in the PreRender event handler.  I don't think that should be a problem, but when I set the parameters it seems to ignore them, so I'm off on a hunt for that now.  Any suggestions would be gratefully appreciated. 

Here's the C# version of the code:

publicList<ReportParameter> GetClientParameters(ReportViewer viewer)

{

        Control paramsArea = FindParametersArea(viewer);        List<ReportParameter> thisParams =newList<ReportParameter>();

        FindParameters(paramsArea, thisParams);

        return thisParams;

}

privateControl FindParametersArea(ReportViewer viewer)

{

      foreach (Control childin viewer.Controls)

     {

          if (child.GetType().Name =="ParametersArea")               return child;

     }

     returnnull;

}

privateList<ReportParameter> FindParameters(Control parent, List<ReportParameter> thisParams)

{

     ReportParameter param;     ReportParameterInfo paramInfo;

     String[] paramValues;     foreach(Control childin parent.Controls)

     {

          //if ( _ParameterControlType.IsAssignableFrom(child.GetType() ) ) - THIS IS THE PART i COULDN'T GET TO WORK PROPERLY

          {

               paramInfo = (
ReportParameterInfo)GetPropertyValue(child,"ReportParameter");

               if (paramInfo ==null )                    continue;

               paramValues = (

String[])GetPropertyValue(child,"CurrentValue");                if (paramValues !=null&& paramValues.Length > 0 )

                {

                       param =
newReportParameter();

                       param.Name = paramInfo.Name;

                       param.Values.AddRange(paramValues);

                       thisParams.Add(param);

                }

          }

          FindParameters(child, thisParams);

     }

     return thisParams;

}

publicObject GetPropertyValue(Object target,String propertyName)

{

     object retVal = target.GetType().GetProperty(propertyName);

     if (retVal !=null)          retVal = target.GetType().GetProperty(propertyName).GetValue(target, null);

     return retVal;

}

 

Re: Getting ReportViewer client parameters at runtime

$
0
0

I wish I could be of more help but I had the same problem with the same method.  I wasn't able to get anywhere with it. Perhaps someone out there with a bit more experience with the report viewer and c# may be able to help.  You were atleast able to get it to compile, I was not. 

 I beleive there are some short comings of the report viewer, or it could just be my inexperience with it.  I have alot more to learn about it.

Re: Getting ReportViewer client parameters at runtime

$
0
0

Hmmm...  Okay.  Thanks for the reply.  I'm hoping someone out there has it in C#.  It appears that there are a couple of differences in the v9 version of ReportViewer that are giving me headaches.  For example, there doesn't appear to be a ParameterControl object in the WebForms anymore and I'm also having some difficulties in the GetPropertyValue method with an "object reference not set to an instance of an object."  If you have c# experience I'd be more than happy to have you look at the code and let me know what you see.  Here's what I have for both those:

public Type _ParameterControlType;

_ParameterControlType = Assembly.GetAssembly(this.EdgeReportViewer.GetType()).GetType("Microsoft.Reporting.WebForms.ReportParameter");

The above at least compiles, but I don't think it's getting the same type reference since I'm looking at ReportParameter and not ParameterControl (which seems to have disappeared from the WebForms object).

This is what it looks like using most of the same code from the example (the change is to the reportviewer instance rather than the class itself)

 //_ParameterControlType = Assembly.GetAssembly(this.EdgeReportViewer.GetType()).GetType("Microsoft.Reporting.WebForms.ParameterControl");The method that's problematic is: 

publicObject GetPropertyValue(Object target,String propertyName)

{return target.GetType().GetProperty(propertyName, BindingFlags.IgnoreCase |BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(target,null);}

It generates the error when evaluating the Instance BindingFlag. 

 Any suggestions would be greatfully accepted. As with most projects, this is a yesterday kind of deadline.

Thanks for any help!

 

Larry

 

Re: Getting ReportViewer client parameters at runtime

$
0
0

I dind't get a c# version, I was refering to the posted code.

Re: Getting ReportViewer client parameters at runtime

$
0
0

John,

   Can you send me the C# code you received?  I'm dealing with almost the same issue and converting this from the VB that was posted is problematic.

Thanks!

 

Larry

Re: Getting ReportViewer client parameters at runtime

$
0
0

This code looks like just the ticket, but my site is all in C#. I noticed that you have sent a C# version to one respondent.  Could you please send it to me as well?  The email address islarry.whipple@gmail.com.

 

Thanks!

 

Larry


Re: Getting ReportViewer client parameters at runtime

$
0
0

Hi!

 Thanks for the code!  I have implemented it in my project however I am having a problem calling the method GetPropertyValue(..)  I don't know what 'target' is.  I understand the propertyName will be the property name from my report, I just don't know what I need to pass in as target.

Thanks!

John

Re: Getting ReportViewer client parameters at runtime

$
0
0

ok. i got the C# code. but my requiremnt is to set the value for the parameter. how can i do this?

 thanks, srik

Re: Getting ReportViewer client parameters at runtime

$
0
0

Hi,

my problem is some thing similar. i have a database which stores data belonging to multiple clients. what i have to do is i have to apply the client ID while showing data in areport. i am using reportviewer for this purpose. i can pass the value for client id only if i add the clientid parameter to prompt. then there is every chance of user changing the value as it will be visible on the reportviewer along with other parameters. so i want to set the appropriate value for this parameter before passing it to the report. i think the code that you have given will work for me.can you please send the equivalent C# code.

 Thanks in advance.

Srik

Re: Getting ReportViewer client parameters at runtime

$
0
0

autofed,

Your code saved my ass. It worked like a charm. Thank you. 

Re: Getting ReportViewer client parameters at runtime

$
0
0

The values of the parameters are stored in the view state of the parameter controls. Unfortunately, as you mentioned, you don't have direct access to those controls at run time. However, you do have access to them through the Controls collection of the ReportViewer, if you know what to look for. The following code will extract the currently selected parameter values. NOTE: this code uses reflection and is dependent on the internal implementation of the parameter controls. This is necessary since the ReportViewer does not expose the values of these controls in any other way.

Public Function GetCurrentParameters(ByVal viewer As Microsoft.Reporting.WebForms.ReportViewer) As ReportParameter()
		Dim paramsArea As Control = FindParametersArea(viewer)
		Dim params As New List(Of ReportParameter)()
		FindParameters(paramsArea, params)
		Return params.ToArray()
	End Function


	Private Function FindParametersArea(ByVal viewer As Microsoft.Reporting.WebForms.ReportViewer) As Control
		For Each child As Control In viewer.Controls
			If child.GetType().Name = "ParametersArea" Then
				Return child
			End If
		Next
		Return Nothing
	End Function


	Private _ParameterControlType As Type = System.Reflection.Assembly.GetAssembly(GetType(Microsoft.Reporting.WebForms.ReportViewer)).GetType("Microsoft.Reporting.WebForms.ParameterControl")
	Private Sub FindParameters(ByVal parent As Control, ByVal params As List(Of ReportParameter))
		Dim param As ReportParameter
		Dim paramInfo As ReportParameterInfo
		Dim paramValues As String()
		For Each child As Control In parent.Controls
			If _ParameterControlType.IsAssignableFrom(child.GetType()) Then
				paramInfo = CType(GetPropertyValue(child, "ReportParameter"), ReportParameterInfo)
				If paramInfo Is Nothing Then Continue For
				paramValues = CType(GetPropertyValue(child, "CurrentValue"), String())
				If Not paramValues Is Nothing AndAlso paramValues.Length > 0 Then
					param = New ReportParameter()
					param.Name = paramInfo.Name
					param.Values.AddRange(paramValues)
					params.Add(param)
				End If
			End If
			FindParameters(child, params)
		Next
	End Sub


	Public Function GetPropertyValue(ByVal target As Object, ByVal propertyName As String) As Object
		Return target.GetType().GetProperty(propertyName, BindingFlags.IgnoreCase Or BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public).GetValue(target, Nothing)
	End Function
 

Re: Getting ReportViewer client parameters at runtime

$
0
0
I don't have access to those events since the controls are rendered automatically in the ReportViewer depending on what type of parameter it is. I'm trying to see if there is a property in the actual parameter creation when creating the report. There has to be because one of my reports that has a dropdown list did a postback whenever the selection changed. But another report didn't. I have to find out how this happened...

Re: Getting ReportViewer client parameters at runtime

$
0
0

What about using TextChanged and SelectedIndex changed event. Make a function where you load your Reportviewer. Call that function everytime there is text changed or selected index changed.


Re: Getting ReportViewer client parameters at runtime

$
0
0

bullpit

Examine your parameters in isPostBack block.

protected void Page_Load(object sender, EventArgs e)
{
  if(isPostBack)
   {
     //EXAMINE
   }
}

 

 

I've been doing this but it doesn't work. If it were a DateTime parameter then it would work because when you change the date in ReportViewer it does a Postback which updates the ReportViewer. Is it possible to always do a Postback whenever a value for a parameter is changed? Even for String parameters that appear as textboxes? This would solve my problem.

Re: Getting ReportViewer client parameters at runtime

$
0
0

Examine your parameters in isPostBack block.

protected void Page_Load(object sender, EventArgs e)
{
  if(isPostBack)
   {
     //EXAMINE
   }
}
 

Re: Getting ReportViewer client parameters at runtime

$
0
0

I am also trying to find how to get the parameters that the user has set when they hit the View Report button. But I think this is what happens when you do a GetParameters when you hit the View Report button on the ReportViewer control:

When you do a GetParameters() it gets the values of the parameters of the report that is already generated on the screen. So if you were to change the parameters and click View Report, in your Page_Load when you call GetParameters(), this is looking at the parameters before your new report is generated. So if you wanted the new parameters that the user has inputted, you would need to wait for the report to get generated then do a postback and use GetParameters.

 If anyone knows how to get the parameter values the user has selected before the report is generated, please let us know.[:^)]

Re: Getting ReportViewer client parameters at runtime

$
0
0

I am having a similar problem. Have you found a solution, specifically to number 1 in the second section of your message?

 CWaitz

Getting ReportViewer client parameters at runtime

$
0
0

I cannot seem to do the following:

 1)  I have a report that uses the ASP.NET 2.0 Report Viewer against a RS2005 report that has parameters.  Some have default values.  One is a text box.  Others are drop-down lists.
2)  I have ShowParameterPrompts = true and am presented the parameter area upon first visit to the page.
3)  I fill in the parameters on the web browser page and click the View Report button
4)  Now, on the server side, I want to examine the parameter values (in the Page_Load event).  When I do a GetParameters on the ServerReport of the ReportViewer, I receive back a collection of the default parameters values, not the values that I just submitted. 

How do I see the parameter values submitted by the client?

Other information I found while investigating this:

1)  If I click on the View Report button again (and again), GetParameters always return the previous set of parameters, not the current values that the client submitted.
2)  If I look at the Request.Forms collections I can see values for controls that have been generated by the ReportViewer control in the parameters area - where the values are different when the client submitts new parameters.
3)  If I do a GetParameters in the pages Page_PreRender event, I see the same behavior.
4)  I can do a walk of the control tree inside the report view control instance and see the various controls created for the parameters area.  Those controls have the Request.Form values in them.
5)  The Report Viewer, load, report refresh and prerender events don't seem to be much help either.

I could hack a solution using the control tree or the Request.Form values, but that's rather inelegant and relies on Micrsoft not changing the ReportViewer control's behavior. 

 Any explanations of what is happening here would be appreciated.  Thanks,

ER Doll

 

Viewing all 20 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>