Select to view content in your preferred language

Question regarding to the results of query task and find task!

2066
4
07-22-2011 02:30 PM
DanDong
New Contributor
HI guys,

I am trying to implement such tool: the user could type something in the textbox, then in the button click event, results containing what the user inputs are returned in a datagrid.

Firstly, I was using the query method. Similar to this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#QueryWithoutMap
I use a textbox to get what the user inputs and then give this string value to one of the query's property: query.text. In esri's sl api page, it says: Text:Shorthand for a literal search text on the display field, equivalent to: where <displayField> like '%%'. The text is case sensitive. This parameter is ignored if the where parameter is specified. You can determine what the display field is for a layer using the ArcGIS Services Directory.

So that means the user needs to type in something only belongs to the display field, otherwise, it won't return any feature found.

Then I tried the find task, similar to this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Find
By using this method, it can find similar string with the user input from all of the fields(or you can specify some fields).
But I also found some shortcommings:
1. The results can only be returned as Alias name&Value (a pair), which means Field name cannot be returned and without it the datagrid cannot be binded to the correct values. (datagrid must be binded to the field name to get the correct values, not alias name)

2. There is only one field name seems receivable, which is the first field that the user's input string is included in. For example, the user types "ch" and in layer 1, there are 4 fields contain "ch" similar data. Only the first field's name and it's alias can be get. Just like what is used in the second sample: <slData:DataGridTextColumn Binding="{Binding Path=FoundFieldName}" Header="Found Field Name" />. FoundFieldName is the alias name and DisplayFieldName is the field name.
So that means only one field's value will be binded to the datagrid, due to the alias name & field name issue....

I am not sure whether my understanding about the find result is correct. Appreciate any experience or any suggestion on how to handle this issue!
0 Kudos
4 Replies
ChristopherHill
Occasional Contributor
We are aware of this issue with FindTask and IdentifyTask returning 'FieldAlias' instead of 'FieldName'. Here is the work around.

Bind to the dictionary instead of the key inside the dictionary like so:
Binding="{Binding  Converter=MyAlaisConverter, ConverterParameter=FoundFieldName,}"

Since you have access to the FeatureLayer fields which contain the field and the alais you can create a custom converter that will lookup the alias from the feature layer fields based on the 'FieldName' then once it has the 'FieldAlais' use that to lookup the value from the dictionary<'FieldAlais',value> then return the value from the KeyValuePair.

.Chris
0 Kudos
ChristopherHill
Occasional Contributor
I have created a solution example of a two ways you can get around the Alias name if you intend on using Xaml binding. One solution uses a value converter and the other uses a different sytax for declaring your binding, which does not require you to use the value converter.

Here is a quick snippet and the sample solution is attached

 <slData:DataGrid x:Name="myDataGrid"  Height="200" Grid.Row="1" AutoGenerateColumns="False">
                <slData:DataGrid.Columns>

                    <!--without converter-->
                    <slData:DataGridTextColumn Header="Object ID(1)">
                        <slData:DataGridTextColumn.Binding>
                            <Binding Path="[Object ID]" />
                        </slData:DataGridTextColumn.Binding>
                    </slData:DataGridTextColumn>

                    <!--with converter-->
                    <slData:DataGridTextColumn Header="Object ID(2)" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=objectid}" />  

                    <slData:DataGridTextColumn Header="Earthquake Date" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=datetime}" />
                    <slData:DataGridTextColumn Header="Depth" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=depth}" />
                    <slData:DataGridTextColumn Header="Earthquake ID" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=eqid}" />
                    <slData:DataGridTextColumn Header="Latitude" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=latitude}" />
                    <slData:DataGridTextColumn Header="Longitude" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=longitude}" />
                    <slData:DataGridTextColumn Header="Magnitude" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=magnitude}" />
                    <slData:DataGridTextColumn Header="Number of Stations" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=numstations}" />
                    <slData:DataGridTextColumn Header="Region" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=region}" />
                    <slData:DataGridTextColumn Header="Source" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=source}" />
                    <slData:DataGridTextColumn Header="Version" Binding="{Binding Converter={StaticResource AliasConverter}, ConverterParameter=version}" />
                </slData:DataGrid.Columns>
            </slData:DataGrid>          
0 Kudos
DanDong
New Contributor
Thank  you Chris! That is very kind of you to share the methods and the codes.

In the two methods, Object ID is the alias name and objectid is the field name right?

I would like to generate the columns in the code-behind, instead of in the xaml. The columns' names are not fixed and they are totally dependent on the layer find task is working on. That's why I need to generate the columns in code-behind.

Any thoughts on how to do that in code-behind?
0 Kudos
ChristopherHill
Occasional Contributor
Thank  you Chris! That is very kind of you to share the methods and the codes.

In the two methods, Object ID is the alias name and objectid is the field name right?

I would like to generate the columns in the code-behind, instead of in the xaml. The columns' names are not fixed and they are totally dependent on the layer find task is working on. That's why I need to generate the columns in code-behind.

Any thoughts on how to do that in code-behind?


You will need to obtain the FieldName and FieldAlias using the featurelayer in the coded behind then just dynamically add columns to your datagrid with the binding just like in xaml.
0 Kudos