title: DataBind Generic "Dynamic" Class to GridView
body: <p>How can I databind a GridView to a class like the following?</p>
  
  <pre><code>public class GenericEntity
  {
      private readonly Dictionary&lt;string, object&gt; properties = new Dictionary&lt;string, object&gt;();
      public object this[string propertyName]
      {
          get
          {
              if (properties.ContainsKey(propertyName))
                  return properties[propertyName];
              else
                  return null;
          }
          set
          {
              if (value == null)
                  properties.Remove(propertyName);
              else
                  properties[propertyName] = value;
          }
      }
  }
  </code></pre>
  
  <p>This class may have any number of properties and there is no way to know any of them on compile time, only on runtime, this is because the properties map directly to columns of a result set from the BD.</p>
  
  <p>How can I databind a list of this GenericEntity class to a GridView? I tried the following but I get the exception of 'class does not contain a property with name...'</p>
  
  <pre><code>var newColumn = new BoundField();
  newColumn.HeaderText = resultsetDescription.FieldDisplayName;
  newColumn.DataField = resultsetDescription.FieldName;
  myGridView.Columns.Add(newColumn);
  
  myGridView.DataSource = GetListOfGenericEntities(args);
  myGridView.DataBind();
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I have implemented the approach mentioned in this <a href="https://stackoverflow.com/questions/882214/data-binding-dynamic-data">SO answer</a> but it still throws the property exception...</p>