Displaying task results in a table
In this post, Tom Brenneman of ESRI Professional Services presents a Web control he developed for displaying task results in a table.
The standard Web ADF controls render task results with a tree view. This is allows multiple results as well as a variety of result types to be displayed in a uniform way. However some applications require that task results be displayed in a table without having to navigate the tree structure of the standard task results. There is an existing sample that illustrates how this can be done by working with custom tasks or application logic that dynamically updates an ASP.NET GridView control.
The custom control I've provided in this post is a little different in that it works with both standard tasks and custom tasks. Using this GridResults control, you can display the results of a task in a grid by simply adding the GridResults as a Task Result Container of the task. The table generated by the GridResults control also includes rows with buttons and check boxes to enable Pan, Zoom, and Select for each feature. This is what the GridResults control looks like in a web application:
As you can see in the example there are also links at the top to you can Select, Unselect, and Zoom to all of the features in the table. By clicking on the column headers you can sort data in the table. What you can’t see in the example above is that this control also supports ASP.NET themes, so you have complete control over the colors, fonts, and text sizes used by the control. Implementing themes for the control is discussed in more detail at the end of this post.
If you are using the Web Mapping Application template, there are slightly different ways to configure the grid than if you are using it in a standard web page. Below are instructions for each approach.
Using the GridResults control in a Web Mapping Application template application
- Install the GridResults web control.
- Using Visual Studio, create a new website using the Web Mapping Application template.
- Right-click anywhere on the Toolbox and click Choose Items...
- Click Browse and Navigate to gridResults.dll (Default location is C:/Program Files/ESRI/ArcGIS GridResults Control).
- Click OK to dismiss the Choose Toolbox Items dialog.
- Open the Source view for Default.aspx.
- Find the Results floating panel at about line 98. Highlight this block and copy it, then paste it immediately below. We are doing this with the Source view so you can be sure that the location you paste the floating panel is still in the left panel div with the rest of the floating panels. You also may want to keep the Results panel and standard task results container "TaskResults1" for tools such as Identify.
- Change the Title property of the new floating panel to "Table Results".
- Delete the entire TaskResults tag (TaskResults2) from the new Table Results panel.
-
Drag gridResults from the Toolbox into the Table Results floating panel (Where the taskResults control used to exist). Your markup should look like the following.
<esri:FloatingPanel ID="FloatingPanel1" runat="server"
BackColor="White" BorderColor="White" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" Font-Size="8pt"
ForeColor="Black" Height="150px" Style="position:relative; margin
bottom:0px;" Draggable="False" Title="Table Results"
TitleBarColor="White" TitleBarHeight="20px"
TitleBarSeparatorLine="True" Transparency="0" Width="100%"
HeightResizable="True" Font-Bold="True" CloseButton="False"
TitleBarForeColor="DarkGray" Expanded="False"
WidthResizable="False" ShowDockButton="True"
ShowDockedContextMenu="True">
<esri_samples:gridResults ID="GridResults1" runat="server"
Height="200px" Style="position: absolute; overflow: auto;"
Visible="True" Width="400px" />
</esri:FloatingPanel> -
To make the grid display with scroll bars in the floating panel, we need to adjust the style attribute of the control. Change the style attribute to the following.
Style="position:absolute; height:100%; width:100%; overflow:auto; left:0px; top:0px;"
- Switch to design view.
- Right-click on GridResults1 and click Properties.
- Set the Map property of the GridResults1 to the name of your map (Map1).
- Use the MapResourceManager to add a map resource to the application.
- Add tasks (such as QueryAttributesTask) to the task manager and configure their properties.
- Click the Smart Tag on your task(s) and click Choose Task Results container.
- Click Add and set the Name of the Buddy Control to GridResults1. If you use the standard TaskResults control with your tasks as well, make sure the standard TaskResults is the last one in the list.
- Click OK to the BuddyControl Collection Editor and run the application.
- When you execute the task, the floating panel will update with a table containing the results.
Using the GridResults control without a floating panel
Use the instructions below if you have created a web application without the Web Mapping Application template. In this case, you will set the style properties appropriately for your application.
- Open your web application in Visual Studio.
- Do steps 3-5 in the instructions from the previous section.
- Add the GridResults control to your page.
- Set the Map and other properties of the GridResults to display appropriately in your application. In the sample I use the following property settings.
<esri_samples:gridResults ID="GridResults1" runat="server" Height="290px" Visible="True" Width="780px" Map="Map1" Style="position:absolute; overflow:auto; z-index: 500; left: 20px; top: 450px; vertical-align:top;" MinWidthOfZoom="0.001" />
- Do steps 15-20 in the instructions from the previous section.
Common properties of the GridResults control to modify
There are two additional properties that you may want to change specifically for your application: MinWidthOfZoom and ZoomExtentExpansionPercentage.
- MinWidthOfZoom – this is the minimum width (or height actually) in map units of the extent rectangle that will be zoomed to. This is particularly useful if the result set is a single point or a very small feature. In this case you could set the minimum extent that the map will zoom to. If you are working with geographic data you may want to make this significantly smaller than the default of 10.
- ZoomExtentExpansionPercent – this is the expansion percentage around the extent of the result set for the map to zoom to. This is useful for defining a margin around the extent of features returned in a result set.
Controlling the appearance of the results control with skins
The GridResults control is actually a Panel control containing a Label control (the resulting table name), Hyperlink controls (The zoom to all button, pan to all button, etc.), and a GridView control. The appearance of these controls honors the styleSheetTheme of your application. Using ASP.NET themes and skins you can control the look and feel of this control in your application. The following are the set of steps to enable themes and configure a skin for the table in the GridResults control. This example modifies the Blue_Bridge theme used by the Web Mapping Application template. If you aren’t using the Web Mapping Application template, you will have to create an appropriate theme for your application before walking through these steps.
- Enable style sheet themes by adding the following tag to your Web.config file.
<pages styleSheetTheme="Blue_Bridge"/>
If you are using the Web Mapping Application template you will want to leave the theme attribute as well, so your tag should look like this.<pages theme="Blue_Bridge" styleSheetTheme="Blue_Bridge"/>
- Open App_themes > Blue_Bridge > Default.skin.
-
Add the appropriate tags to control the appearance of the Label, Hyperlink, and GridView controls contained within this control. Below is an example tag to make the symbology of the grid similar to the Blue_Bridge theme. You can copy and paste this into your skin file as an example.
<asp:GridView runat="server" BackColor="White" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="White" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="#79A8D1" Font-Bold="True" ForeColor="Black"/>
<AlternatingRowStyle BackColor="#C0D4E4" />
</asp:GridView> - Save and run the application. When you execute the task, you should now see the results displayed in the table with a light blue header and a blue background for the alternating item (See the graphic at the top of this post for an example).
Try it out
- For an example of the GridResults control in action, see this sample application.
- You can download the control and try it out. An installer has been included for convenience.
- You can also download the source code used to create this control and customize it any way you like.
Note: This control and its source code are provided for example purposes only and do not constitute a supported ESRI product. Please direct questions about this control to the Comments section of this blog. You may also post questions about using the ArcGIS Server Web ADF to the ESRI User Forums.
Update (February 26, 2008): I fixed a problem with the GridResults control where sorting didn't work right when there are multiple results. This problem is most evident when you use the GridResults control with the Identify tool. This new control is available on ArcScripts here: http://arcscripts.esri.com/details.asp?dbid=15452 .
# re: Displaying task results in a table
# re: Displaying task results in a table
# re: Displaying task results in a table
This looks great! Thank you so much for your work on this. Does it require SP3? I received an error adding it to my toolbar and I suspect that may be why. Also, I have a field marked as a hyperlink field in my map document. Does this by chance support hyperlinked fields?
Thanks again!
# re: Displaying task results in a table
# re: Displaying task results in a table
This is very helpful.
I'm trying to build this on ArcGIS Server for Java.
I wanted to use Icefaces or Richfaces fot building a such complex Table.
Unfortanly, I can't get working the combination of Iceface/ArcGIS JSF resp. Richfaces/ArcGIS JSF library.
Has anybody a JAVA solution for this example?
Thanks,
Tom
# re: Displaying task results in a table
Where is GridResults_Display.js
I don't see it in the source?
# re: Displaying task results in a table
# re: Displaying task results in a table
# re: Displaying task results in a table
Getting the GridResults to work with the Identify tool is a little trickier. The identify tool is a custom tool integrated into the Web Mapping Application template instead of a common task. So we need to modify its code a bit to work with the GridResults. First we need to modify its code file to use ITaskResultsContainer instead of TaskResults (the type for the standard tree-based task results).
In MapIdentify.vb or MapIdentify.cs
[VB]
To:Change:
[C#]
Change:
To:
Then at the the top of MapIdentify.vb or MapIdentify.cs:
[VB]
Change:
To:
[C#]
Change:
To:
We also need to point the identify class to the grid results on startup of the application. In the code-behind file for the default page, Default.aspx.vb or Default.aspx.cs, at about line 45:
[VB]
Change:
To:
[C#]
Change:
To:
Now, instead of putting the GridResults control into its own floating panel, replace TaskResults1 with GridResults1 in Default.aspx. Your markup should look like the following.
Make sure you don’t change the name of the Results floating panel. The JavaScript for the Identify tool uses that name to open and close the panel. Next you need to modify that JavaScript to get the identify tool add the activity indicator to the correct control.
Change line 30 of display_mapidentify.js from
To
Now your identify tool should use the GridResults control for its display. There are other dependencies in display_mapidentify.js on the name of the Results floating panel being named “Results”. So if you use a different name for your results floating panel, make sure to update those references as well.
# re: Displaying task results in a table
# re: Displaying task results in a table
# PrintTask
# re: Displaying task results in a table
# re: Displaying task results in a table
The "Hyperlinking in task results" blog from July shows an example (in C++ though I'm using VB) of how to override the ExecuteTask method to create a hyperlink in the results. Can this be done with the GridResults Control also?
# re: Displaying task results in a table
# re: Displaying task results in a table
# re: Displaying task results in a table
# re: Displaying task results in a table
# Identify on more that one layer
# re: Displaying task results in a table
Michael,
Yes it looks like my code doesn't do sorting well when there are multiple table results. Currently the control just tracks column and sort order but it should store a collection of objects with info for how each table should be sorted. I'm not sure if I will have time to fix this but if you want to tackle it yourself RefreshGrid in gridresults.cs is a good place to start. If I get a chance to fix it, I'll repost.
# re: Displaying task results in a table
# re: Displaying task results in a table
# re: Displaying task results in a table
# re: Displaying task results in a table
# re: Displaying task results in a table
# DataTable to Gridresults
# re: Displaying task results in a table
Is there a way to adjust what fields display in the gridresults? I don't need them all.
# Limiting Fields
TToutant,
You can limit the number of fields a couple of ways. If you're not coding, use the mxd by going into the layer properties and choosing the fields that should be visible. Or, using .NET you can list the fields you'd like to return:
string list = "Field1,Field2,Field3";
String[] flds = list.Split(',');
ESRI.ArcGIS.ADF.StringCollection scoll = new ESRI.ArcGIS.ADF.StringCollection(flds);
queryfilter.SubFields = scoll;
# re: Displaying task results in a table
Is there a way to change the field names? I have a join in my mxd, so the field names are really long.
# re: Displaying task results in a table
You need to add the table to a Dataset, then send the dataset to the DisplayResults function of ITaskResultsContainer. Here is the code:
System.Data.DataTable datatable = qfunc.Query(null, lids[layer_index], queryfilter);
DataSet ds = new DataSet();
ITaskResultsContainer tskRC = GridResults1;
if (datatable.Rows.Count > 0)
{
ds.Tables.Add(datatable);
tskRC.DisplayResults(null, null, null, ds);
}
else
{
string heading = "No results found";
string detail = "No results found";
SimpleTaskResult str = new SimpleTaskResult(heading, detail);
tskRC.DisplayResults(null, null, null, str);
}
I'm trying to use this code to display the dataset to the gridviewResults but getting the following error.
No parameterless constructor defined for this object.
It works fine with the identify tool but doesn't work for the query.
# re: Displaying task results in a table