Using ESRI Silverlight API 3.1, .NET Framework 4.0, ArcGIS Server 10.0
Is there a way to update an attribute in the code behind without looping through the featureLayer.Graphics? Or a way to call FeatureLayer.Update without losing the edits made? We cannot hard code our layers into the xAML because we need them to be dynamic.
Ideally we would like to run something similar to a QueryTask, returning a set of features that we could update the attributes of.
To work around this we have attempted to use the FeatureLayer where and update functions. For this test there is only a single FeatureLayer in my map.
The where and update successfully revises the layer to have a single entry -
FeatureLayer testLayer = (ESRI.ArcGIS.Client.FeatureLayer)featureLayer;
testLayer.UpdateCompleted += UpdateTask_ExecuteCompleted;
testLayer.Where = "TEST_ID=12345";
testLayer.Update();
// Update Event
private void UpdateTask_ExecuteCompleted(object sender, System.EventArgs args)
{
foreach (GraphicsLayer graphicsLayer in testEditor.GraphicsLayers)
{
if (graphicsLayer is FeatureLayer)
{
FeatureLayer featureLayer = graphicsLayer as FeatureLayer;
foreach (Graphic feature in featureLayer.Graphics)
{
if (Convert.ToInt32(feature.Attributes["TEST_ID"]) == 12345)
{
feature.Attributes["NAME"] = "Renamed";
}
}
}
}
This event handler will loop through my feature layer – now queried to 1 record, and update the name attribute.
The issue at this point is that on my display I now only have the single record showing. If I reset the where clause to “1=1” and run an update I lose my edit.
I can SaveEdits before I reset the layer which will save my edit. But I am hoping for a solution that will still allow the user to save all the edits at a single time when they are finished. Is there a way to update and maintain my edit?
This all is a workaround due to not being able to query to get the feature to edit. If there is a way of doing that without iterating through every Graphic that would be the ideal solution to this. Are we missing the big picture here?