Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 24, 2013 08:18 AM by Decker Dong - MSFT
Member
86 Points
272 Posts
Jan 22, 2013 03:44 PM|LINK
Hi
please take a look at this article which Binds XML file to a GridView
http://www.magic-dev.com/bind_gridview_to_xml_file.htm
everything is ok but my xml looks like this. it has an extra node inside and the code does not work with it
<contacts>
<newContacts> <contact name="Ibrahim Abu Marasa" phone="76576" /> <contact name="Mohammed" phone="65346362" />
<newContacts>
<oldContacts> <contact name="Ibrahim Abu Marasa" phone="76576" /> <contact name="Mohammed" phone="65346362" />
<oldContacts> </contacts>
All-Star
118619 Points
18779 Posts
Jan 24, 2013 01:32 AM|LINK
Hi,
Your Xml isn't correct in its defination.
Please change to this:
<contacts> <newContacts> <contact name="Ibrahim Abu Marasa" phone="76576" /> <contact name="Mohammed" phone="65346362" /> </newContacts> <newContacts> <contact name="Ibrahim Abu Marasa" phone="76576" /> <contact name="Mohammed" phone="65346362" /> </newContacts> </contacts>
Then you can use DataTable or DataSet.ReadXml to load the xml contents and then do what you want.
Jan 24, 2013 06:41 AM|LINK
yes i know the xml in my code is correct
please keep to the subject it seems noone just reads the question!
Jan 24, 2013 07:23 AM|LINK
keyvan1 please keep to the subject it seems noone just reads the question!
Again I said that your node of your xml isn't right. You have to rechange it and do binding.
Jan 24, 2013 08:04 AM|LINK
i know it was just a sample
what should the code look like!
Jan 24, 2013 08:18 AM|LINK
keyvan1 i know it was just a sample what should the code look like!
You have to use XDocument to read out properties and do binding:
var result = from item in XDocument.Load("xxx.xml").Descedants("contact") select new { Name = item.Attribute("name").Value, Phone = item.Attribute("phone").Value };
Then bind the result to GridView.
keyvan1
Member
86 Points
272 Posts
Bind XML file to GridView problem
Jan 22, 2013 03:44 PM|LINK
Hi
please take a look at this article which Binds XML file to a GridView
http://www.magic-dev.com/bind_gridview_to_xml_file.htm
everything is ok but my xml looks like this. it has an extra node inside and the code does not work with it
<contacts>
<newContacts>
<contact name="Ibrahim Abu Marasa" phone="76576" />
<contact name="Mohammed" phone="65346362" />
<newContacts>
<oldContacts>
<contact name="Ibrahim Abu Marasa" phone="76576" />
<contact name="Mohammed" phone="65346362" />
<oldContacts>
</contacts>
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Bind XML file to GridView problem
Jan 24, 2013 01:32 AM|LINK
Hi,
Your Xml isn't correct in its defination.
Please change to this:
Then you can use DataTable or DataSet.ReadXml to load the xml contents and then do what you want.
keyvan1
Member
86 Points
272 Posts
Re: Bind XML file to GridView problem
Jan 24, 2013 06:41 AM|LINK
yes i know the xml in my code is correct
please keep to the subject it seems noone just reads the question!
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Bind XML file to GridView problem
Jan 24, 2013 07:23 AM|LINK
Hi,
Again I said that your node of your xml isn't right. You have to rechange it and do binding.
keyvan1
Member
86 Points
272 Posts
Re: Bind XML file to GridView problem
Jan 24, 2013 08:04 AM|LINK
i know it was just a sample
what should the code look like!
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Bind XML file to GridView problem
Jan 24, 2013 08:18 AM|LINK
You have to use XDocument to read out properties and do binding:
var result = from item in XDocument.Load("xxx.xml").Descedants("contact")
select new
{
Name = item.Attribute("name").Value,
Phone = item.Attribute("phone").Value
};
Then bind the result to GridView.