Query with Order By Field Online

This sample demonstrates performing a query, sorting the results based on a specified field, and adding the results to the map and a FeatureDataGrid. To use the sample, perform a search for an owner name in the upper right corner of the application.

In the sample's code-behind, a QueryTask is used to query a MontgomeryQuarters map service layer based on the name entered in the search box. The Query.OrderByFields property is set to an OrderByField object that specifies results should be sorted with SortOrder.Ascending based on the OWNER_NAME field. The features found are then added to a graphics layer and are displayed on the map and in the FeatureDataGrid.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.OrderByFieldQuery"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <esri:SimpleRenderer x:Key="SelectRenderer">
                <esri:SimpleRenderer.Symbol>
                    <esri:SimpleFillSymbol>
                        <esri:SimpleFillSymbol.ControlTemplate>
                            <ControlTemplate>
                                <Path x:Name="Element" Fill="Transparent" Stroke="Black" StrokeThickness="1.5"
							  Cursor="Hand">
                                    <VisualStateManager.VisualStateGroups>
                                        <VisualStateGroup x:Name="SelectionStates">
                                            <VisualState x:Name="Unselected" />
                                            <VisualState x:Name="Selected">
                                                <Storyboard>
                                                    <ColorAnimation Storyboard.TargetName="Element"
															Storyboard.TargetProperty="(Path.Fill).(SolidColorBrush.Color)" 
															To="Yellow" Duration="0:0:.25" />
                                                    <ColorAnimation Storyboard.TargetName="Element"
															Storyboard.TargetProperty="(Path.Stroke).(SolidColorBrush.Color)" 
															To="Cyan" Duration="0:0:.25" />
                                                    <DoubleAnimation Storyboard.TargetName="Element" 
															 Storyboard.TargetProperty="StrokeThickness"
															 To="3" Duration="00:00:.25" />
                                                </Storyboard>
                                            </VisualState>
                                        </VisualStateGroup>
                                    </VisualStateManager.VisualStateGroups>
                                </Path>
                            </ControlTemplate>
                        </esri:SimpleFillSymbol.ControlTemplate>
                    </esri:SimpleFillSymbol>
                </esri:SimpleRenderer.Symbol>
            </esri:SimpleRenderer>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="5" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <esri:Map x:Name="MyMap" WrapAround="True" Grid.Column="0"
                  Background="WhiteSmoke" PropertyChanged="MyMap_PropertyChanged">
            <esri:ArcGISDynamicMapServiceLayer 
                    Url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/MontgomeryQuarters/MapServer"/>
            <esri:GraphicsLayer ID="MontgomeryParcels" Renderer="{StaticResource SelectRenderer}" 
                           />
        </esri:Map>
        <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" />
        <Grid Margin="5" Grid.Column="2" Background="White" VerticalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="40" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0" Margin="2" Orientation="Horizontal">
                <TextBox Name="SearchTextBox" Text="JOHN" VerticalAlignment="Center" Width="100"
                         HorizontalAlignment="Left" Margin="2,2,5,2" />
                <Button Content="Search by owner name" Click="Button_Click" 
                        Margin="2" VerticalAlignment="Center" HorizontalAlignment="Right" />
            </StackPanel>
            <ScrollViewer Grid.Row="1">
                <esri:FeatureDataGrid x:Name="MyDataGrid"
				Map="{Binding ElementName=MyMap}" 
				GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[MontgomeryParcels]}" />
            </ScrollViewer>
        </Grid>
    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014