Welcome to ESRI Blogs

Hyperlinking in task results

At the User Conference, some of you asked how to include hyperlinks in your task results. This is useful if your features have corresponding web sites. You want users to be able to click directly on a hyperlink from a field in the results panel instead of typing the URL in a browser.

There are two ways to approach hyperlinking. If you don’t want to add any custom code to your application, you can add a field to the feature class that stores the complete HTML for the hyperlink. You should include the tag, attributes, and text for the hyperlink, like this:

<a href=http://www.esri.com target=_blank>ESRI</a>

This is how it would look in the ArcMap table view:

Hyperlink HTML in ArcMap table view 

This will create the following result in the ADF for a task result. You don’t have to do anything extra to create the link; the HTML gets interpreted automatically:

Task results with link to ESRI website

Clicking this link will open http://www.esri.com.

The second way to create a hyperlink in the task results is to construct the hyperlink programmatically with existing attribute content. The example below shows one way to do this with the Query Attributes task. You’ll need to subclass the out-of-the-box query task and override the ExecuteTask method to get access to the result dataset from the query (available via the Results property).

   public class CustomQueryTask: QueryAttributesTask

    {

        public override void ExecuteTask()

        {

            base.ExecuteTask();

            if (Results is System.Data.DataSet)

            {

                System.Data.DataSet dataset = (System.Data.DataSet)Results;

                System.Data.DataTable datatable = dataset.Tables[0];

                foreach (System.Data.DataRow datarow in datatable.Rows)

                {

                    string val = (string)datarow["CNTRY_NAME"];

                    string updatedval = "<a target='_blank' href='http://www.google.com/search?q=" + val + "' >" + val + "</a>";

                    datarow["CNTRY_NAME"] = updatedval;

                }

            }

        }

    }

The results of the above code might appear like this in the TaskResults control at runtime:

Task results with links to countries

For an additional example of hyperlinking in task results, see Tom Brenneman’s sample on ArcScripts.

-Sterling Quinn, with Derek Weatherbe and Rex Hansen

Published Tuesday, July 17, 2007 10:45 AM by sterlingdq
Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Hyperlinking in task results

This is great. However, it doesn't seem to work if the hyperlink attribute is sent to a Gridview who's fields are autogenerated. Does anyone know how to get this to work? I have a map with numerous layers and I do not want to create Gridview's for every layer just to get a hyperlink field if possible. Thanks for your help.
Wednesday, July 25, 2007 12:33 PM by Mike Bialousz

# re: Hyperlinking in task results

Hey there- Do you know how I could go about completely changing the table design? I want to change the look of the table so it is not the standard greyness, and also hide certain fields. I also dont want to have the field at the top of the table displayed inside the table as well. However, when I try to delete columns other than attribute columns, it says 'access denied, cannot delete geometry column' for example... All I can get working is changing values, as you do above. I also looked at hiding fields in my mxd, but if you have the shape field hidden you cannot zoom to a result and if it is checked you get a shape_area and shape_length column added to the results, which is undesirable to customer. When I try other methods that Ive found, such as using a taskresultnode: Dim trn_ds2 As TaskResultNode = taskResults.CreateTaskResultNode(Nothing, Nothing, Nothing, results, True, True) then looping thru: For Each tvpn2 As TreeViewPlusNode In trn_ds2.Nodes And I can get the results looking exactly how I want (wrote a sub that takes the table html, and gets needed values and spits them out as formatted html), but when a user clicks on the check box to highlight/select a feature, the custom content of the table gets erased and the standard results reappear :(. Do you know of any way using your method to completely change the view of the results at the lowest node (replacing table), or to make the results from using the taskresultsnode table replacement permanent, as what happens with your code? Or is results modification limited to changing values in existing rows? Thanks for any help you can give, this is quite hard to figure out and get working properly. Roy
Thursday, September 13, 2007 9:24 PM by roy jackson

# re: Hyperlinking in task results

Hi Everyone, I can customize the task results but I cannot get the identify icon working on the web application.When I use the identify icon, it says "Identify Error: Object reference not set to an instance of an object" on the web app. Would somebody know any solution to this. Best Regards, Prashanth
Friday, January 18, 2008 1:26 PM by Prashanth

# re: Hyperlinking in task results

How do you get this code to work with the Identify tool?
Friday, February 08, 2008 7:54 AM by Bob B.

# re: Hyperlinking in task results

Where would you implement the second method where you can hyperlink a field programmatically.

Wednesday, February 20, 2008 10:38 AM by carrierkh

# re: Hyperlinking in task results

If you are trying to get hyperlinks to work with the identify tool you have to customize the MapIdentify.cs or MapIdentify.vb, here is a link to the page where this is explained in further detail. Note that the code on this page was taken from an earlier post by Kevin Criss. http://forums.esri.com/Thread.asp?c=158&f=2269&t=247399
Wednesday, April 30, 2008 6:51 AM by carrierkh

# re: Hyperlinking in task results

i woluld like to add a hyperlink for Layername and by clicking that the local file(saved in a harddisk) should open..

Please let me know how to move on this...

Regards,

Parshu

Tuesday, June 03, 2008 12:19 AM by parshu

# re: Hyperlinking in task results

Hi, I would like to create a hyperlink on a map parcel which in turn will open a web page that displays a crystal report about that parcel or display the CR reportviewer on the same page. The parameter will be the parcel number or property address. Is there anything written on this subject? If you have several articles that I can put together, that will be fine, too. I appreciate your help, Regards Angelle aadlay@simivalley.org (805)583-6868
Monday, August 04, 2008 9:39 AM by ANGELLE ADLAY

# re: Hyperlinking in task results

i do very thanks for host!!
Thursday, November 06, 2008 11:50 PM by leepf7211

# re: Hyperlinking in task results

I have a question that may be a simple question but has been stumping me.  I want to be able to put shapefiles or comma separated value files in the Results pane so the user can download them.  It works fine on the intranet because the URL is made with the local server name.  How do I get it to switch to our domain name for the public sites?

Sunday, November 30, 2008 7:36 AM by JHanscom

# re: Hyperlinking in task results

How about a hyperlink to open a file, such as an image that is linked? In our case, it would be a file which launches another program, or it could be to open a PDF file. Thank you.
Friday, May 29, 2009 12:00 PM by Chris

# re: Hyperlinking in task results

Thank you sir for posting the tips. Its really helpful in hyperlinking the websites. But more specifically is there any way that I can hyperlink using field as raster or pdfs directly instead of creating a webpage.
Tuesday, December 15, 2009 7:27 AM by Ramakrishna

Leave a Comment

(required) 
required 
(required)