The queryattributestask control enables you to explain itly define the parameters used to query values in a field. this control enhances the basic query capability of the searchattributestask. at runtime, The queryattributestask query can provide a drop down list of Preset choices or a textbox for general text entry. each query can also utilize A validator to restrict the values entered. in addition, multiple queries can be grouped together to produce a single result. only feature layers in resources provided by a mapresourcemanager can be used. the results are provided as an ADO. net dataset to be displayed in a taskresults control. A queryattributestask creates a single query on one map layer. the query may have compound criteria. for example, you can define a query on a cities layer that selects cities with a population greater than a value entered by the user, and with a name that begins with a value entered by the user.
- Add supporting controls to the page
In order to take full advantage of the queryattributestask control, a number of supporting controls must be available. set up a Web application with mapresourcemanager and map controls using their discussion topic as a guide. add a taskresults control using that control's discussion topics as a guide. at runtime, The taskresults control will display the results of queryattributestask. users can then interact with the results to change map extent, display selected features, or re-execute the task. taskresults also displays a message to the user while the query executes.
To hide the query form when the application starts up, and to allow the user to call up the form from a link on the page, add a menu control from the standard ASP. net navigation tools, and then add a taskmanager from the ArcGIS Web controls toolbox group. if you want to display the query form immediately upon application startup, you can skip adding these controls.
Be sure to set the buddycontrol property of the TaskManager to the menu control you added. also set the map property of the taskresults control to the map control you added, If you want users to see results highlighted on the map when selected.
- Add a queryattributestask Control
In Visual Studio, display the prepared web form in design mode, select the toolbox and expand the ArcGIS Web controls tab. drag and Drop a queryattributestask control into the TaskManager control; or, if you did not add a taskmanager control, just drag the queryattributestask onto the page. your page might resemble the following layout, arranged using a table:
- Set the required properties for the queryattributestask Control
In design mode, click the queryattributestask, which will display the Smart Tag arrow in the upper right of the control. click on this arrow to display the Smart Tag menu. this Menu displays common properties that you can set, though others are available in the Properties window for the control.
A. Task results container: Click the first item in the Smart Tag menu to choose the task results container, or click the taskresultscontainers property button in the Properties window. this brings up the buddycontrol collection editor. click Add to add an item to the collection. with the taskresults1 item selected, in the right side of the dialog, click the drop-down list and select the taskresults control you added earlier. this is where the queryattributestask will place results when the user executes a query.
B. Set up the query: Click the second item in the Smart Tag menu to edit the query, or click the predefinedquery attribute button in the Properties window. this opens the query attributes editor form. the editor form allows you to create a query for users to interact. you can create a simple query with a single value for users to enter, or a complex query with compound criteria. the example shown below queries a layer with two criteria: city name and population size. in this example, cities are found that have a name that starts with the value the user enters, and that have a population greater than a value the user enters.
- In the resource manager drop-down list, select the mapresourcemanager control added earlier.
- In the resource drop-down list, select the resource item that contains the layer you want to allow users to query.
- In the layer drop-down list, select the layer that you want users to query.
- In the query entries section, click Add to create a new query clause. this displays the form entry editor. in the label text box, enter the text that you want to display to the user for this query item. next, select the associated field from the drop-down list. this is the field that is queried in this query item. choose the operator that compares the value entered by the user to the field values. note that if using 'like', no wildcard character is added by default to the user's value, and partial text values are not matched. you need to modify the where expression with the custom where expression option (see below ).
- Optionally, You may set a default value or create a pick list for users to choose from. the default value displays in the input box. the user may accept this value or change it. if you choose the show pick list option, you need to specify a list of items. the user must choose from among these values in a drop-down list. the user cannot enter an arbitrary value if you choose the pick list option. you may enter values manually in the pick list, or click the get sample values button to retrieve the unique values of the field from the layer. be aware that this can retrieve a very large number of values.
- You may also choose to validate the user's input. this is recommended both for a better user experience and for filtering out malicious input. validation can be done with a range of values or using regular expressions. see texts or online resources on regular expressions for information and common regular expressions. you may also include an error message to display if the user's input fails validation.
- When finished setting up the form entry item, click OK to close the dialog. The form entry item will be added to the query entries in the query attributes editor.
- If you want to create a compound query with multiple criteria, click Add in the query attributes editor to add additional query form items. for each form entry item you add, the user is prompted to enter a value.
- By default, multiple form entry items are queried with "and" criteria. in the example above, only cities that match both the name and the population values entered by the user will be found. to change the concatenation rules to use or, you must modify the query using the custom where expression option.
Custom where expression:You can use the custom where expression option to create or modify the selection expression. to use this option, check the box on the query attributes editor and then enter or modify the expression in the expression text box. you can use the insert field option to insert a field from the layer selected for the query. you can also use the "insert user input Placeholder" to add placeholders (e.g ., "{0}") for text that users wocould enter.
In the example below, the where expression has been modified with the form entry editor so that a wildcard (%) is used to compare the user's value with names in the layer field. in this case, names that begin with the value entered by the user are matched.
C. Visibility of the queryattributestask Control: If you added menu and taskmanager controls, you can have the query form not display at startup. instead, the form displays when the user clicks the query link in the menu control. to hide the Query Form at startup, select the queryattributestask control, and in the Property Window, set the visible property to false.
- Setting the position of Query Form
By default, the queryattributestask form appears in a floating window, which the user may drag to a new position within the web page. the opening position does not necessarily correspond to its position on the Web page design form. if preferred, the query window may be fixed at a specific position.
To fix the position of the query form at a specific location, set the position style of the queryattributestask or a containing control or Div. to set the style, switch the web page from design view to HTML view in Visual Studio. find the queryattributestask in the page listing. insert a style attribute within the control tag, and set its position properties to specific values. use "position: absolute" to set the Query Form at an exact position on the page. use "position: relative" to fix the position relative to its placement to other controls. in the following example, we use relative placement is used to ensure the query window is placed within a table cell:
<td> <esriTasks:QueryAttributesTask style="position:relative;top:5px;left:0px;" ID="QueryAttributesTask1" runat="server" ...> </esriTasks:QueryAttributesTask> <td>
When fixing the position of the query window, you may want to set the closebutton, draggable, expandcollapsebutton, heightresizable and widthresizable properties to false to disallow modifying the Query Form. setting draggable to false disallows moving the query window.
- Other properties for queryattributestask
Some of the properties you may wish to modify for your application include:
- Title: Displayed at the top of the query form to the user. you shoshould change this from the default, which is the ID of the control. choose a title that describes what the query does. an example wocould be, "Find cities where... ".
- Buttontext: Text for the button the user clicks to execute the query.
- Maxrecords: Maximum number of features found by the query. Default is 50.
- Featureselectioncolor: After query results display, and the user checks the box next to a feature, the feature is highlighted with this color on the map.
- Showdetailsintable: Whether to display feature attributes in the query results for each feature.
- Using the queryattributestask at runtime
Using the queryattributestask is similar to using the searchattributestask, doesn't that the user sees more text clues for the form items, and multiple entry form items can be added by the site designer. an example of the query form the user might see wocould be:The user enters values for each form item, then clicks find. The results are displayed in the taskresults control output. See taskresults for a discussion and examples of using the results from a query.