Common Task results
Common_TaskResults_CSharp\TaskResultsWebSite\DataTableResult.aspx.cs
// Copyright 2010 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.
// 

public partial class DataTableResult : System.Web.UI.Page
{
    protected void Toolbar1_CommandClick(object sender, ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolbarCommandClickEventArgs 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.
        switch (toolbarCommandClickEventArgs.CommandName)
        {
            case ("ExecuteQuery"):
                // Get the map resource item to be queried and make sure the underlying resource is initialized
                ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem mapResourceItem = 
                    MapResourceManager1.ResourceItems.Find("MapResourceItem0");
                if (!mapResourceItem.Resource.Initialized)
                    mapResourceItem.InitializeResource();

                // Create a query functionality to use in executing the query
                ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality commonQueryFunctionality = 
                    mapResourceItem.Resource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), 
                    "addDataResultQueryFunctionality") as ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality;

                // Create a query filter and specify a generic where clause.  Also specify that geometries not be
                // returned to improve performance.
                ESRI.ArcGIS.ADF.Web.QueryFilter adfQueryFilter = new ESRI.ArcGIS.ADF.Web.QueryFilter();
                adfQueryFilter.WhereClause = "OBJECTID < 100";
                adfQueryFilter.ReturnADFGeometries = false;

                // Execute the query
                System.Data.DataTable resultsTable = commonQueryFunctionality.Query(null, "0", adfQueryFilter);

                // One method of displaying the results is to place the results table in a dataset and then pass 
                // that dataset to DisplayResults.  This method will result in default formatting of the resulting
                // TaskResultNodes
                System.Data.DataSet resultsDataSet = new System.Data.DataSet("Results");
                resultsDataSet.Tables.Add(resultsTable);

                TaskResults1.DisplayResults(null, null, null, resultsDataSet);


                // An alternative method of displaying the table is to explictly create TaskResultNodes.  This 
                // method allows custom configuration of those nodes, providing control over behaviors such as 
                // node expansion

                //// 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 data table
                //ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode resultsTreeViewPlusNode =
                //    TaskResults1.CreateDataTableNode(resultsTable, true, false, true, null, "Query Results");

                //// Expand the data 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);
                break;
        }
    }
}