Consider the following scenario:
You create a layer template report that you want to contain a feature hyperlink. For example, as part of the report for a zip code, you want to have a hyperlink to a page that shows which county the zip code is in. The website is http://www.whitepages.com and by providing the zip code you can go directly to the search page for the zip code. The actual URL for zip code 28208 would be as shown as http://www.whitepages.com/search/FindZip?where=28208
You put the following computation into the HyperLink field for a Label or TextBox, but the ZIP value is not inserted as expected: ="?http://www.whitepages.com/search/FindZip?where="+ZIP
The problem is that the HyperLink field in an Active Reports report is static; it cannot be computed on the fly. To resolve this issue, update the value of the HyperLink field using a script.
Solution:
Below is an example of the code-behind script that gets the value of the ZIP field and updates the HyperLink field of the Label named "Hyperlink1". The example also shows how to handle fields whose value is numeric (i.e. updating the HyperLink field of the label named "Hyperlink2").
Note that the method name must match the name of the Details section. In this example, the Details section of the report is named "Detail1".
public void Detail1_Format() { Label hyperlink1 = rpt.Sections["Detail1"].Controls["Hyperlink1"] as Label; string zip = rpt.Fields["ZIP"].Value as string; hyperlink1.HyperLink = "http://www.whitepages.com/search/FindZip?where=" + zip; hyperlink1.Text = "White Pages Zip Code Search"; Label hyperlink2 = rpt.Sections["Detail1"].Controls["Hyperlink2"] as Label; string zip_value = Convert.ToString( rpt.Fields["ZIP"].Value); hyperlink1.HyperLink = "http://www.whitepages.com/search/FindZip?where=" + zip_value; hyperlink2.Text = "White Pages Zip Code Search"; }
Comments
0 comments
Article is closed for comments.