Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:14:58+00:00 2026-06-01T12:14:58+00:00

I am reading data from XML like this: (Contacts.xml) <?xml version=1.0 encoding=utf-8 standalone=yes?> <!–LINQ

  • 0

I am reading data from XML like this:
(Contacts.xml)

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <!--LINQ to XML Contacts XML Example-->
    <?MyApp 123-44-4444?>
    <contacts>
      <contact>
        <name>Patrick Hines</name>
        <phone type="home">206-555-0144</phone>
        <phone type="work">425-555-0145</phone>
        <address>
          <street1>123 Main St</street1>
          <city>Mercer Island</city>
          <state>WA</state>
          <postal>68042</postal>
        </address>
      </contact>
      <contact>
        <name>Gretchen Rivas</name>
        <phone type="mobile">206-555-0163</phone>
        <address>
          <street1>123 Main St</street1>
          <city>Mercer Island</city>
          <state>WA</state>
          <postal>68042</postal>
        </address>
      </contact>
    </contacts>

My code for getting data from XML file:
(contacts.cs)

public class Contact
    {
//static members
public static string fLocation;

//private members
private string name;
private List<PhoneNumber> pNumber;
private Adress cAdress;

//public members
public Adress CAdress
{
    get { return cAdress; }
}
public List<PhoneNumber> PNumber
{
    get { return pNumber; }
}
public string Name
{
    get { return name; }
}

//Constructor
public Contact(string _name, List<PhoneNumber> _pNumber,Adress _cAdress)
{
    name = _name;
    pNumber = _pNumber;
    cAdress = _cAdress;
}

public static List<Contact> Get()
{
    List<Contact> output = new List<Contact>();

    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<PhoneNumber> pNumber = new List<PhoneNumber>();

        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;
    }
}

}

And I want to somehow bind to Gridview:
(default.aspx)

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="ObjectDataSource1">
        <Columns>
            <asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" 
                SortExpression="Name" />
            <asp:DynamicField DataField="CAdress" HeaderText="CAdress" />
            <asp:DynamicField DataField="PNumber" HeaderText="PNumber" />
        </Columns>
    </asp:GridView>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="Get" 
        TypeName="LINQtoXML_WebForms.Contact"></asp:ObjectDataSource>

Any ideas how to bind for example Contact.PhoneNumber.number + “-” Contact.PhoneNumber.numberType to colomn?

i.e.: 774-6655-252 - mobile

Thanks.

When I run it, it shows me an error:

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:14:59+00:00Added an answer on June 1, 2026 at 12:14 pm

    I think you either have to add meta information to your class or use the approach I’d use – write a method yourself instead of using objectdatasource object.

    For example Linq to XML

    public List<Contact> GetContacts()
    { 
        XDocument doc = XDocument.Load("path_to_some_file.xml");
    
        var contacts = from o in doc.Descendants("contact")
                       select new Contact()
                       {
                          Name = (string)o.Element("Name"),
                          Phone = (string)o.Element("Phone")
                       };
    
         return contacts.ToList();
    }
    

    and then just bind it in code-behind to your control:

    GridView1.DataSource = GetContacts();
    GridView1.DataBind();
    

    Hope you get the idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading an XML file that looks like this: <?xml version=1.0 encoding=utf-8?> <VehicleList> <Vehicle>
After reading data from XML source I like to be able to show one
I am reading data from XML file using from..select linq query, the data is
I planning on reading profile data from a xml file in JSP. Now i
I get this error when reading some data from an SQL column then converting
I am reading data from another system that returns XML that provides the following
I am reading data from multiple serial ports. At present I am using a
I'm reading data from a serial port using an event listener from the SerialPort
I'm reading data from a stream into a char array of a given length,
I am reading data from a file that has, unfortunately, two types of character

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.