Select to view content in your preferred language

Accessing Attribute Indexes

2297
4
06-20-2011 01:36 AM
MichaelMelaku
Deactivated User
Salute All,

Well, i got a requirement to pass an attribute index as a queryString and perform a query operation at the backend. This numeric value should then be parsed to give the attribute name so that i can use it for the queryTask while passing the string URL as a parameter to construct the querytask.

My question is ... is it possible to get an attribute index and parse it to get the attribute name from the application logic? Please any code snippet or conceptual brief would certainly help.
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
A FeatureLayer is providing the 'LayerInfo' property whose 'Fields' property is returning the list of fields ans so a way to index all the fields.
So the FeatureLayer seems to be what you are looking for. Even if you don't need the FeatureLayer in your map, you can create one by code just in order to get the list of fields. In this case, instantiate the feature layer, set the URL and call 'Initialize'. On event 'Initialized' we'll be able to get the list of fields.
0 Kudos
MichaelMelaku
Deactivated User
Thanks Dominique. That was very helpful. Let me put it in place and see how it goes. I'll let u know.
0 Kudos
MichaelMelaku
Deactivated User
Well, Strange. For some reasons, the LayerInfo of the featurelayer is always returning null. I don't know what i'm missing. For review, the below is my snippet.

Private void IndexExtractor()
{
     FeatureLayer ft = new FeatureLayer()
     {
            ID = "MyFeatureLayer",
            Url = "http://michael/ArcGIS/rest/services/zones/FeatureServer/1"
     };

     ft.Initalized += new EventHandler<EventArgs>(ft_Initalized);
    
     Map.Layers.Add(ft);

     List<ESRI.ArcGIS.Client.Field> LayerFields = new List<ESRI.ArcGIS.Client.Field>();
     ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo myFeatureLayerInfo = ft.LayerInfo;
     foreach (ESRI.ArcGIS.Client.Field Fields in myFeatureLayerInfo.Fields)
    {
          LayerFields.Add(Fields);
    }
}

void ft_Initalized(object sender, EventArgs e)
{
     ft.Initalize();
     Graphic newGraphic = new Graphic();
     ft.Graphics.Add(newGraphic);
}

Everytime it executes, the LayerInfo returns null. Any idea?

Thanks a mil.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The LayerInfo is only available after the layer has been initialized.

So this should be not null in ft_initialized.

Side note : since you are adding your layer in a map, it's not useful to call Initialize on it :

 
void ft_Initalized(object sender, EventArgs e)
{
FeatureLayer ft = sender as FeatureLayer;
////ft.Initalize(); Not needed
Graphic newGraphic = new Graphic(); // need to add geometry here
ft.Graphics.Add(newGraphic);
 
///ft.LayerInfo  should be non null here
}
 
0 Kudos