Select to view content in your preferred language

Convert a string to a link in a query result

1299
10
12-07-2010 03:28 AM
PaulHuppé
Occasional Contributor
Hi,

I am doing a query task and getting results back.  In the feature set I get back, in the attributes, one of the attributes is an ID which I want to use in a URL.  In the results grid, I would like to see just a button or a hyperlinked word which would open a new window to the URL I would build.

Currently, when the query task completes, the results grid is populated using:

QueryDetailsDataGrid.ItemsSource = args.FeatureSet.Features;


Obviously, this will have to change if I want to insert some type of link.  I have tried the following code:

                List<Graphic> lstGraphics = new List<Graphic>();
                foreach (Graphic g in args.FeatureSet.Features)
                {
                    if (g.Attributes.ContainsKey("GEOSCANREC"))
                    {
                        g.Attributes["GEOSCANREC"] = "<a href=\"http://geopub.nrcan.gc.ca/html/view_e.php?id=" + g.Attributes["GEOSCANREC"] + "\">GO</a>";
                    }
                    lstGraphics.Add(g);
                }
                QueryDetailsDataGrid.ItemsSource = lstGraphics;


which inserts the URL in the grid, but it is not an active link.  Is there a way to change that so the user can click to open the link in a new window?

Thanks,
Paul
0 Kudos
10 Replies
PaulHuppé
Occasional Contributor
Now that I have the hyperlink button working, I want to do something a little more complicated.  When I click the hyperlink button, I would like to both open a window and navigate to the URL specified, as is currently the case, but at the same time, I would like to execute a method in code behind.  I tried adding a click event handler to the hyperlink as follows:

            // Add a link to display the GeoSCAN record in a popup
            string attributeName = "GEOSCANREC";
            DataTemplate cellTemplate =
                    (DataTemplate)System.Windows.Markup.XamlReader.Load(@"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007""> 
                            <HyperlinkButton NavigateUri=""{Binding Attributes[" + attributeName +
                    @"], StringFormat='http://geoscan.ess.nrcan.gc.ca/starweb/geoscan/servlet.starweb?path=geoscan/geoscanfastlink_e.web&amp;search1=R=\{0\}'}"" 
                             TargetName=""_blank"" Click=""DoSomethingOnClick"" ToolTipService.ToolTip=""{StaticResource strDisplayGeoscanRecord}"" ><Image Source=""/Minimal;component/Images/DotDotDot.png"" Width=""18"" Height=""22"" />
                            </HyperlinkButton> </DataTemplate>");
            QueryDetailsDataGrid.Columns.Add(new DataGridTemplateColumn()
            {
                Width = new DataGridLength(115),
                Header = LanguageResources.strGeoscanHeader.ToString(),
                CellTemplate = cellTemplate
            });


What that does is give an error as in the attachment.  I get the same result if I try to move the click event to a onleftmousedown event handler on the Image instead.

Is there a way to get the two things done on a single click?
0 Kudos