title: Using Anonymous type in Gridview
body: <p>I want to use an anonymous type as source to a GridView. But it will be filtered first using a dropdownlist. Let me explain: I have a type I defined as follows:</p>
  
  <pre><code>    IEnumerable&lt;object&gt; data = new[]{
      new{Name="McClure Wallace", Id=1, Sal=10000d, Age=29}, 
      new{Name="John Jones", Id=2, Sal=12000d, Age=27}, 
      new{Name="Gloria Flowhart", Id=3,Sal=14000d, Age=21}
              . . .
      }; 
  </code></pre>
  
  <p>I use this as source to a dropdownlist:</p>
  
  <pre><code>    ddlEmployee.DataSource=data;
      ddlEmployee.DataTextField = "Name";
      ddlEmployee.DataValueField = "Id";
      ddlEmployee.DataBind();
  </code></pre>
  
  <p>When the user selects an item from the list I want to get the corresponding object and bind it in a Gridview:</p>
  
  <pre><code>    var sel = ddlEmployee.SelectedItem.ToString();
  
     var selData = from d in data where **d.Id= sel** select d;
     gvSearchResults.DataSource = selData;
     gvSearchResults.DataBind();
  </code></pre>
  
  <p>But the problem is that since I will get d as an object, it throws an error on d.Id. </p>
  
  <p>How can I fix this. Please note that I may not be able to change definition of 'data' as this is controlled outside the app. I am only showing here for clarity.</p>