Layer Column Names to Dropdown

3706
3
02-15-2012 05:51 AM
BrianLeroux
Occasional Contributor III
Is there a way to get the column names of a dynamic map service into a drop down. What i am trying to do is build a tool that would allow me to select a field name from the drop down and enter a search term for that field to filter the layer. Any help is appreciated.
0 Kudos
3 Replies
OrlandoCarvajal
New Contributor III
To get the list of all fields for all sublayers of a dynamic layer you can try GetAllDetails(,); for a particular sublayer use GetDetails(int,,).
0 Kudos
JenniferNery
Esri Regular Contributor
You can use the following code:
XAML
  <StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
  <ComboBox x:Name="LayerNames">
   <ComboBox.ItemTemplate>
    <DataTemplate>
     <TextBlock Text="{Binding Value.Name}"/>
    </DataTemplate>
   </ComboBox.ItemTemplate>
  </ComboBox>
   <ComboBox x:Name="FieldNames" DataContext="{Binding ElementName=LayerNames, Path=SelectedItem}"
       ItemsSource="{Binding Value.Fields}">
    <ComboBox.ItemTemplate>
    <DataTemplate>
     <TextBlock Text="{Binding Name}"/>
    </DataTemplate>
   </ComboBox.ItemTemplate>
  </ComboBox>
  </StackPanel>


Code-Behind
   var layer = new ArcGISDynamicMapServiceLayer() { Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/MapServer" };
   layer.GetAllDetails((a, b) =>
    {
     if (b != null)
      MessageBox.Show(b.Message);
     else    
      LayerNames.ItemsSource = a;
    });
0 Kudos
BrianLeroux
Occasional Contributor III
jenniferdnery- Thanks for the sample. I will give that a try.
0 Kudos