Select to view content in your preferred language

Sort Query Results in Combo Box

820
2
03-27-2013 07:00 AM
BrandonIves
Emerging Contributor
Hi,

I am trying to reproduce the attribute query example found here:

http://resources.esri.com/help/9.3/arcgisserver/apis/silverlight/samples/start.htm#AttributeQuery

I would like to sort the query results. Is there an easy way to do this? I tried this:

InitializeComponent();
QueryTask queryTask = new QueryTask("http://gisadev/ArcGIS/rest/services/CUProperties_Query/MapServer/0");
queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
queryTask.Failed += QueryTask_Failed;

ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();

// Specify fields to return from initial query
query.OutFields.AddRange(new string[] { "NAME" });
query.OutFields.Sort();
// This query will just populate the drop-down, so no need to return geometry
query.ReturnGeometry = false;


// Return all features
query.Where = "1=1";
queryTask.ExecuteAsync(query, "initial");
}

I think this is only sorting the first field which is object ID. Any suggestions would be appreciated.
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
0 Kudos
BrandonIves
Emerging Contributor
You can use the OrderByFields property. Documentation here :  http://resources.arcgis.com/en/help/silverlight-api/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tas...


Thanks for the reply dbroux.

I ended up using the same method as mentioned in this thread:

http://forums.arcgis.com/threads/30014-Query-task-on-SDE-layer


[INDENT] var sortedList = featureSet.Features.OrderBy(f => (string) f.Attributes["STATE_NAME"]).ToList();

            foreach(var graphic in sortedList)
            {
                System.Diagnostics.Debug.WriteLine(graphic.Attributes["STATE_NAME"]);
            }[/INDENT]
0 Kudos