Common Task results
Common_TaskResults_VBNet\TaskResultsWebSite\GraphicsLayerResult.aspx.vb
' Copyright 2011 ESRI
' 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See the use restrictions.
' 

Imports Microsoft.VisualBasic
Imports System
Public Partial Class GraphicsLayerResult
  Inherits System.Web.UI.Page
  Protected Sub Toolbar1_CommandClick(ByVal sender As Object, ByVal toolbarCommandClickEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolbarCommandClickEventArgs)
    ' Check to make sure our custom command was clicked.  This is not necessary in this case since there 
    ' is only one item on the toolbar, but is included here for demonstration.
    Select Case toolbarCommandClickEventArgs.CommandName
      Case ("SelectCitiesInExtent")
        ' Get the map resource item to be queried and make sure the underlying resource is initialized
        Dim mapResourceItem As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem = MapResourceManager1.ResourceItems.Find("MapResourceItem0")
        If (Not mapResourceItem.Resource.Initialized) Then
          mapResourceItem.InitializeResource()
        End If

        ' Create a query functionality to use in executing the query
        Dim commonQueryFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality = TryCast(mapResourceItem.Resource.CreateFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), "addDataResultQueryFunctionality"), ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)

        ' Create a spatial filter and initialize its geometry to the current map extent
        Dim adfSpatialFilter As ESRI.ArcGIS.ADF.Web.SpatialFilter = New ESRI.ArcGIS.ADF.Web.SpatialFilter()
        adfSpatialFilter.Geometry = Map1.Extent

        ' Execute the query on the first layer in the resource
        Dim resultsTable As System.Data.DataTable = commonQueryFunctionality.Query(Nothing, "0", adfSpatialFilter)

        ' Convert the query results to a graphics layer
        Dim resultsGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer = ESRI.ArcGIS.ADF.Web.Converter.ToGraphicsLayer(resultsTable)

        ' Apply the layer format of the queried layer to the query results
        Dim layerFormat As ESRI.ArcGIS.ADF.Web.UI.WebControls.LayerFormat = ESRI.ArcGIS.ADF.Web.UI.WebControls.LayerFormat.FromMapResourceManager(MapResourceManager1, "MapResourceItem0", "0")
        layerFormat.Apply(resultsGraphicsLayer)

        ' Select each feature in the graphics layer so its selected symbol shows up
        For Each row As System.Data.DataRow In resultsGraphicsLayer.Rows
          row(resultsGraphicsLayer.IsSelectedColumn) = True
        Next row

        ' Specify that the layer be rendered in the client tier so it has client-side functionality
        ' (e.g. highlighting and mapTips on hover)
        resultsGraphicsLayer.RenderOnClient = True

        ' One method of displaying the results is to place the graphics layer in a dataset and then pass 
        ' that dataset to DisplayResults.  This method will result in default formatting of the resulting
        ' TaskResultNodes
        Dim resultsDataSet As System.Data.DataSet = New System.Data.DataSet(String.Format("Results", resultsTable.Rows.Count))
        resultsDataSet.Tables.Add(resultsGraphicsLayer)

        TaskResults1.DisplayResults(Nothing, Nothing, Nothing, resultsDataSet)


        ' An alternative method of displaying the graphics layer is to explictly create TaskResultNodes.
        ' This method allows custom configuration of those nodes, providing options such as displaying
        ' a legend and expanding the nodes

        ' Create a parent node for the results and assign it a remove-only context menu
        'ESRI.ArcGIS.ADF.Web.UI.WebControls.TaskResultNode headingTaskResultNode =
        '    new ESRI.ArcGIS.ADF.Web.UI.WebControls.TaskResultNode(string.Format("Results ({0})",
        '    resultsTable.Rows.Count));
        'TaskResults1.SetupContextMenu(TaskResults1.RemoveOnlyContextMenu, headingTaskResultNode);

        '// Create a node with the results graphics layer
        'ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode resultsTreeViewPlusNode =
        '    TaskResults1.CreateDataTableNode(resultsGraphicsLayer, true, false, true, null, "Query Results");

        '// Expand the layer node and assign it a remove-only context menu
        'resultsTreeViewPlusNode.Expanded = true;
        'TaskResults1.SetupContextMenu(TaskResults1.RemoveOnlyContextMenu, resultsTreeViewPlusNode);

        '// Add the data node under the parent node and call EnsureVisible to make sure the parent node
        '// is not collapsed.  Note that EnsureVisible needs to be called after the node is added.
        'headingTaskResultNode.Nodes.Add(resultsTreeViewPlusNode);
        'resultsTreeViewPlusNode.EnsureVisible();

        '// Display the custom node by passing it to DisplayResults
        'TaskResults1.DisplayResults(null, null, null, headingTaskResultNode);

        ' Copy the TaskResults control's callback results to the Toolbar so they are processed
        ' on the client
        Toolbar1.CallbackResults.CopyFrom(TaskResults1.CallbackResults)
    End Select
  End Sub
End Class