Welcome Guest Search | Active Topics | Sign In | Register

Databinding grid to xmldatasource control Options
Brad Coble
Posted: Wednesday, December 17, 2008 8:27:09 AM
Rank: Member
Groups: Member

Joined: 12/17/2008
Posts: 16
Do you have any example code to do this?
eo_support
Posted: Wednesday, December 17, 2008 8:56:47 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,088
Hi,

I do not believe the Grid works with XmlDataSource directly because the Grid is two-demension and XmlDataSource is Hierarchical. The easiest way for you to work with XmlData is to use XmlDocument and XPath directly. It will be something like this:

Code: C#
//Load the xml data first
XmlTextReader reader = new XmlTextReader(your_xml_file_name.xml);
XmlDocument doc = new XmlDocument();
doc.Load(reader);

//Get the node list
XmlNodeList nodes = doc.SelectNodes(your_xpath);

//Populate the grid from the node list
grid1.DataSource = nodes;
grid1.DataBind();


The XPath you pass to SelectNodes would dedicate what you wish to feed the Grid. This is similar to the XPath property on XmlDataSource object. In addition to the above code, you would also need to define all Grid columns first and each column’s DataField first. In the case of binding to Xml data, the DataField should be set to the corresponding attribute name.

The data binding is one way only. The Grid does not update the Xml file for you.

Hope this helps.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.