title: LINQ to XML & bind to Gridview
body: <p>I am reading data from XML like this:
  (Contacts.xml)</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
      &lt;!--LINQ to XML Contacts XML Example--&gt;
      &lt;?MyApp 123-44-4444?&gt;
      &lt;contacts&gt;
        &lt;contact&gt;
          &lt;name&gt;Patrick Hines&lt;/name&gt;
          &lt;phone type="home"&gt;206-555-0144&lt;/phone&gt;
          &lt;phone type="work"&gt;425-555-0145&lt;/phone&gt;
          &lt;address&gt;
            &lt;street1&gt;123 Main St&lt;/street1&gt;
            &lt;city&gt;Mercer Island&lt;/city&gt;
            &lt;state&gt;WA&lt;/state&gt;
            &lt;postal&gt;68042&lt;/postal&gt;
          &lt;/address&gt;
        &lt;/contact&gt;
        &lt;contact&gt;
          &lt;name&gt;Gretchen Rivas&lt;/name&gt;
          &lt;phone type="mobile"&gt;206-555-0163&lt;/phone&gt;
          &lt;address&gt;
            &lt;street1&gt;123 Main St&lt;/street1&gt;
            &lt;city&gt;Mercer Island&lt;/city&gt;
            &lt;state&gt;WA&lt;/state&gt;
            &lt;postal&gt;68042&lt;/postal&gt;
          &lt;/address&gt;
        &lt;/contact&gt;
      &lt;/contacts&gt;
  </code></pre>
  
  <p>My code for getting data from XML file:
  (contacts.cs)</p>
  
  <pre><code>public class Contact
      {
  //static members
  public static string fLocation;
  
  //private members
  private string name;
  private List&lt;PhoneNumber&gt; pNumber;
  private Adress cAdress;
  
  //public members
  public Adress CAdress
  {
      get { return cAdress; }
  }
  public List&lt;PhoneNumber&gt; PNumber
  {
      get { return pNumber; }
  }
  public string Name
  {
      get { return name; }
  }
  
  //Constructor
  public Contact(string _name, List&lt;PhoneNumber&gt; _pNumber,Adress _cAdress)
  {
      name = _name;
      pNumber = _pNumber;
      cAdress = _cAdress;
  }
  
  public static List&lt;Contact&gt; Get()
  {
      List&lt;Contact&gt; output = new List&lt;Contact&gt;();
  
      XDocument data = XDocument.Load(fLocation);
  
      var query = from c in data.Descendants("contact")
                  orderby c.Element("name").Value
                  select c;
  
      foreach (var item in query)
      {
          List&lt;PhoneNumber&gt; pNumber = new List&lt;PhoneNumber&gt;();
  
          foreach (var PhoneNumbers in item.Elements("phone"))
          {
              pNumber.Add(new PhoneNumber(PhoneNumbers.Value,PhoneNumbers.Attribute("type").Value));
          }
  
          Adress cAdress = new Adress(item.Element("address").Element("street1").Value,
              item.Element("address").Element("city").Value,
              item.Element("address").Element("state").Value,
              item.Element("address").Element("postal").Value);
  
          output.Add(new Contact(item.Element("name").Value,pNumber,cAdress));
      }
  
      return output;
  }
  
  //subclasses
  public class Adress
  {
      private string street;
      private string city;
      private string state;
      private string postal;
  
      public string Postal
      {
          get { return postal; }
      }          
      public string State
      {
          get { return state; }
      }
      public string City
      {
          get { return city; }
      }
      public string Street
      {
          get { return street; }
      }
  
  
      public Adress(string _street,string _city, string _state, string _postal)
      {
          street = _street;
          city = _city;
          state = _state;
          postal = _postal;
      }
  }
  
  public class PhoneNumber
  {
      private string number;
      private string numberType;
  
  
      public string NumberType
      {
          get { return numberType; }
      }
      public string Number
      {
          get { return number; }
      }
  
  
      public PhoneNumber(string _number, string _phoneNumberType)
      {
          number = _number;
          numberType = _phoneNumberType;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And I want to somehow bind to Gridview:
  (default.aspx)</p>
  
  <pre><code>        &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
          DataSourceID="ObjectDataSource1"&gt;
          &lt;Columns&gt;
              &lt;asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" 
                  SortExpression="Name" /&gt;
              &lt;asp:DynamicField DataField="CAdress" HeaderText="CAdress" /&gt;
              &lt;asp:DynamicField DataField="PNumber" HeaderText="PNumber" /&gt;
          &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
      &lt;asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="Get" 
          TypeName="LINQtoXML_WebForms.Contact"&gt;&lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p>Any ideas how to bind for example Contact.PhoneNumber.number + "-" Contact.PhoneNumber.numberType to colomn?</p>
  
  <p>i.e.: <code>774-6655-252 - mobile</code></p>
  
  <p>Thanks.</p>
  
  <p>When I run it, it shows me an error:</p>
  
  <blockquote>
    <p>Could not determine a MetaTable. A MetaTable could not be determined for the data source 'ObjectDataSource1' and one could not be inferred from the request URL. Make sure that the table is mapped to the dats source, or that the data source is configured with a valid context type and table name, or that the request is part of a registered DynamicDataRoute.</p>
  </blockquote>