Report Design
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Report Design
Message Icon Topic: Passing parameters from a HyperLinkField Post Reply Post New Topic
Author Message
KMeyer
Newbie
Newbie


Joined: 03 Jan 2007
Location: Australia
Online Status: Offline
Posts: 22
Quote KMeyer Replybullet Topic: Passing parameters from a HyperLinkField
    Posted: 04 Feb 2007 at 12:17am
This may have been covered else where, but I have yet to find any posts in Google and it may help other newbies stuck in a rut like I was. For the purists it might not be technically correct but it simply works with minimum coding.
 
I was looking for a reduced code/smart tags quick and dirty solution for printing a form type report. A typical example would be to pass a discrete parameter value, an invoice number for example from another page to print an invoice in the ReportViewer.
I wanted to use Request.QueryString if at all possible and initially tried without success in the CrystalReportSource properties Report/Parameters/(Collection).
 
All the programming examples I found were correct no doubt, but seemed long winded for what should be a simple enough task and I was not keen on first trying to understand it all and then having to dump a page of code every time I had a report that needed a parameter passed from another page. To quote from the first page of chapter 16 of Brians published book "you first need to know that parameters are very complicated to work with."  
 
The Parameters (Collection) has a specify controlID option to pass a parameter value, most the examples I found, show a dropdownlist populating this. After a couple days trying to find a simple solution I thought I would try using a HiddenField control and see if it would work and was pleasantly surprised, it works like a treat.
 
I created my Parameter Field in the usual manner in the report designer and then on the aspx page containing the CrystalReportViewer I dropped a HiddenField control from the Toolbox. I then added the following to the page load. (C#)

protected void Page_Load(object sender, EventArgs e)

{

HiddenField1.Value = Request.QueryString["ComplaintID"];

}

In this case I wanted to print a form from a record selected in a DetailsView HyperLinkField on another page.
 
I then updated the properties of CrystalReportSource so that my report parameter was controlled by the HiddenField value. All done with one line of code and a couple of mouse clicks.
 
I hope this saves some one else a heep of time and having to get their heads around all the Crystal Reports syntax out there in the examples I found.
 
Kim
 
 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 04 Feb 2007 at 2:30am
Hi Kim,

Thanks for posting all this info on the forum for us. However, I'm confused by one part.

(Disclaimer: I just finished spending the past 8 hour working on the Subreports chapter. My brain is fried and it's 2:30 AM here).

I understand how you are passing the information from the querystring onto the hidden ASP.NET form variable. But then you said that you updated the properties of the report source so that your report parameter is controlled by the HiddenField value and you did this with one line of code. How is the HiddenField 'controlling' the parameter? Do you mean that you are just passing the value to the parameter or is something else going on here?

Also, I haven't looked at how CR 2005 handles parameters, but did they implement new properties of the object model so that its easier to set parameter values now (without writing 20 lines of code)?

A few more details would be greatly appreciated.

Ok, time for bed now.  
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
KMeyer
Newbie
Newbie


Joined: 03 Jan 2007
Location: Australia
Online Status: Offline
Posts: 22
Quote KMeyer Replybullet Posted: 04 Feb 2007 at 5:42pm
Sorry Brian,
I could not find a way to paste a screen shot of the properties dialog which would explain it at a glance. So I will do it by steps, many will already know how send a value to another page via a HyperLinkedField or the other url options.
Lets assume we have already designed our Crystal report with a parameter field, could be CustomerID for example and in the CrystalReportViewer tasks "Enable Report Parameter Prompting" is ticked per default.
This presents the generic Crystal prompt when a end user navigates to the web page in question. If we want to simply view & print this report based on supplying a value from a custom webform without prompting the end user to enter the details, in the past it would seem 20 lines of code were needed to supply a discrete parameter to a report.
In VS2005 I believe the intregration with .net 2.0 may be a little tighter than previous versions and most of the examples I found were for .net 1.1
 
1. Open your page containing the CrystalReportViewer that is expecting a parameter to be passed when it runs the report assigned to it
2. Drag & drop a HiddenField control from the VS Toolbox onto the page.
3. Add the following to your page load to populate the HiddenField.Value value at run time, replace "CustomerID" with your own value.

HiddenField1.Value = Request.QueryString["CustomerID"];

4. Click on your CrystalReportSource and navigate to the properties explorer and expand the "Report" option and select the Parameters (Collection) within.
5.  In the Parameter Collection Editor now being displayed click the "Add" button.
6. Select your report parameter which will be visable in the dropdown selector top right hand side of the Editor.
7. Imediately underneath this tick the "Specify ContolID" option, this will expose all contols on the page in another dropdown and then select your HiddenField (default name is HiddenField1) and click "OK" , your done its that simple.
This will automatically update the Crystal report parameter with the HiddenField1.Value at run time
Now every time your user is directed to this from another page which has passed a parameter value the report will preview ready printing or exporting without prompting the user for input.
I hope everyone understands steps involved, as per my original post 1 line of .net code added to the page and a few mouse clicks. No need to write any Crystal logic into the page at all, smart tags all the way.
 
Regards
Kim
 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 04 Feb 2007 at 11:00pm
Ahhh, very nice. Yes, this is definitely new to CR.NET 2005. I knew that they were doing a lot with smart tags now, but I haven't researched it yet. That's great how they have the parameter collection integrated into the properties window like that. I'm looking forward to getting the XI book finished so I can dig into the new features of CR.NET 2005.

Thanks for the tip!

Edited by BrianBischof - 04 Feb 2007 at 11:01pm
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.029 seconds.