title: CRM 2011 - How to set data in records from subgrid in Entity using C# code
body: <p>I am making a plugin in CRM 2011. The plugin is taking data from the Entity's subgrid by using fetchXML, making some calculate with the data and at the end of the plugin I want to set the new calculated data back in the subgrid, but I can't ... </p>
  
  <p>I tried few ways to do that like:</p>
  
  <p>(1)</p>
  
  <pre><code>    private static OptionSetValue CreateOptionSet(int optionSetValue)
      {
          OptionSetValue optionSetInstance = new OptionSetValue();
          optionSetInstance.Value = optionSetValue;
          return optionSetInstance;
      }
  </code></pre>
  
  <p>(2)</p>
  
  <pre><code>    public void setVal(Entity entity, string attr, object val)
      {
          if (entity.Attributes.Contains(attr))
          {
              entity[attr] = val;
          }
          else
          {
              entity.Attributes.Add(attr, val);
          }
      }
  </code></pre>
  
  <p>and just </p>
  
  <pre><code>paid["zbg_paidamount"] = 400;
  
  
  payment.Attributes["zbg_suggestedamount"] = paidVal;
  </code></pre>
  
  <p>But nothing works... </p>
  
  <p>I am thinking maybe is from the type of the data that I am trying to set but not sure. </p>
  
  <p>Please if you can help me I am desperate.</p>
  
  <p>Thanks</p>