I have modified the sample identify code http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify to display the identify results from 3 layers into 3 different datagrids. One of the fields in each data grid has data that needs to be a hyperlink. Currently I am using this code (see below) to get one of the data grids to display a field as a hyperlink but I am unsure how to modify it to work for all 3 data grids. Any thoughts - I am willing to try a different code if anyone has one. //Hyperlink private void IdentifyDetailsDataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { try { string s = e.Row.DataContext.ToString(); //Check for the field name "Website". if (s.Contains("Website")) { string[] sSplit = s.Split(','); string[] link = sSplit[1].Split(']'); DataGridColumn column = this.IdentifyDetailsDataGrid.Columns[1]; FrameworkElement fe = column.GetCellContent(e.Row); FrameworkElement result = GetParent(fe, typeof(DataGridCell)); if (result != null) { DataGridCell cell = (DataGridCell)result; //Set the URL to empty sring if found a null value. //if (String.IsNullOrEmpty(link[0].Trim())) if (link[0].Trim() == "Null" || link[0] == null) link[0] = String.Empty; cell.Content = new URLField() { url = link[0] }; DataTemplate dt = this.Resources["HyperlinkButtonTemplate"] as DataTemplate; cell.ContentTemplate = dt; } } } catch { } } private FrameworkElement GetParent(FrameworkElement child, Type targetType) { object parent = child.Parent; if (parent != null) { if (parent.GetType() == targetType) { return (FrameworkElement)parent; } else { return GetParent((FrameworkElement)parent, targetType); } } return null; } } public class URLField { public string url { get; set; } }
The following is the code that I am using to separate out my fields and layers into separate data grids: public void ShowFeatures(List<IdentifyResult> results) { _dataItems = new List<DataItem>(); if (results != null && results.Count > 0) { foreach (IdentifyResult result in results) { Graphic feature = result.Feature; string title = result.Value.ToString() + " (" + result.LayerName + ")"; _dataItems.Add(new DataItem() { Title = title, Data = feature.Attributes }); var fieldsToDisplay = new List<string>() { "School Name", "Address", "Zip", "Phone", "Website", "School District" }; var attributesToDisplay = new Dictionary<string, object>(); foreach (var item in feature.Attributes) if (fieldsToDisplay.Contains(item.Key)) attributesToDisplay[item.Key] = item.Value; if (result.LayerId == 4) IdentifyDetailsDataGrid.ItemsSource = feature.Attributes; IdentifyDetailsDataGrid.ItemsSource = attributesToDisplay; if (result.LayerId == 9) IdentifyDetailsDataGrid2.ItemsSource = feature.Attributes; IdentifyDetailsDataGrid2.ItemsSource = attributesToDisplay; if (result.LayerId == 14) IdentifyDetailsDataGrid3.ItemsSource = feature.Attributes; IdentifyDetailsDataGrid3.ItemsSource = attributesToDisplay; }
Thanks!