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 Mar 1, 2011, 4:39 AM
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 27, 2010, 2:07 AM
http://bhushanbharat83.blogspot.com/2010/11/binding-treeview-dynamically-in-aspnet.html
adil ahmedPosted Oct 19, 2009, 7:48 AM
Hi how i hide Id to display in treeview
aaaaa aaaaaPosted Feb 11, 2009, 1:04 AM
how we can bind data with treeview within sqlserver in asp.net