| View previous topic :: View next topic |
| Author |
Message |
sek
Joined: 26 Mar 2010 Posts: 30
|
Posted: Thu Apr 22, 2010 6:56 am Post subject: HOW TO BIND XML FILE DATA TO A Tree View Control. |
|
|
hi all .,
I am new to handling xml files.
I am trying to bind my xml files data to a Tree view control.
my Xml File data is like this.
<?xml version="1.0"?>
<Items>
<FoodItems>
<item>
Pizza
</item>
<Price>
14.45
</Price>
</FoodItems>
<FoodItems>
<item>
Noodles
</item>
<Price>
30.00
</Price>
</FoodItems>
<Books>
<item>
C#
</item>
<price>
120.50
</price>
</Books>
</Items>
Using C# .net how can we bind to Tree View Control.
Thanks in advance. _________________ Sekhar |
|
| Back to top |
|
 |
rajesh
Joined: 26 Mar 2010 Posts: 43
|
Posted: Thu Apr 22, 2010 7:28 am Post subject: |
|
|
Hi Sekhar.,
I feel that the Following code will Solve your Problem
public void bindData(string path)
{
trvXmlData.Nodes.Clear();
if (File.Exists(path))
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(fs);
using (DataSet ds = new DataSet())
{
ds.ReadXml(new XmlNodeReader(doc));
foreach (DataTable tab in ds.Tables)
{
TreeNode ParentNode = new TreeNode((string)tab.TableName);
trvXmlData.Nodes.Add(ParentNode);
foreach (DataRow row in tab.Rows)
{
foreach (DataColumn col in tab.Columns)
{
TreeNode ChildNode = new TreeNode((string)row[col]);
ParentNode.ChildNodes.Add(ChildNode);
}
}
}
fs.Close();
}
}
}
I executed it And it is working ., Enjoy it.
[/list] _________________
***************
Best Regards
Rajesh Mani.
Nyros Technologies. |
|
| Back to top |
|
 |
|