To bind the TreeView control to XML data, I have taken the XmlDataSource in which I have define an Xpath and a DataFile.
Here is my sample code:
<asp:XmlDataSource ID="PageDataSource" runat="server" XPath="/PageTitle" DataFile="~/App_Data/PageTitle.xml" />
<asp:TreeView ID="PageTreeView" runat="server" DataSourceID=" PageDataSource ">
<DataBindings>
<asp:TreeNodeBinding DataMember="Id" TextField="#InnerText" />
<asp:TreeNodeBinding DataMember="Tite" TextField="#InnerText" />
<asp:TreeNodeBinding DataMember="PageUrl" TextField="#InnerText" />
</DataBindings>
</asp:TreeView>
In the page load simply write:
protected void Page_Load(object sender, EventArgs e)
{
PageDataSource.XPath = "/PageTitle";
PageTreeView.DataBind();
}
Lastly, here is the XML file:
<?xml version="1.0" encoding="UTF-8"?>
<PageTitle>
<Page>
<Id>1</Id>
<Tite>This is my testing</Tite>
<PageUrl>mybook /1/1.aspx</PageUrl>
</Page>
<Page>
<Id>2</Id>
<Tite>This is my testing</Tite>
<PageUrl> mybook /2/2.aspx</PageUrl>
</Page>
</PageTitle>


sharad patilPosted Feb 28, 2011, 11:39 PM EST
I have 2 xml files one file name is Admin.xml and second file name is User.xml. As on logon if Admin gets login then i want to bind Admin.xml file to treeview and at Users User.xml to bind in treeview.. it would be possible in treeview at runtime to bind any xml file. pl rply urgently. thank you
Bharat BhushanPosted Nov 26, 2010, 9:07 PM EST
http://bhushanbharat83.blogspot.com/2010/11/binding-treeview-dynamically-in-aspnet.html
adil ahmedPosted Oct 19, 2009, 3:48 AM EDT
Hi how i hide Id to display in treeview
aaaaa aaaaaPosted Feb 10, 2009, 8:04 PM EST
how we can bind data with treeview within sqlserver in asp.net