Wednesday, 25 December 2013

Bind XML to TreeView control

In this article we are going to see how to bind the XML to TreeView Control, Make a xml which consists of navigate url and text value.

<?xml version="1.0" encoding="utf-8" ?>
  <Menu value="Home" url="~/Homes.aspx" />
  <Menu value="Employee" url="~/Employee.aspx">
    <Menu value="Add Employee" url="~/AddEmployee.aspx" />
  <Menu value="Admin" url="~/Adm.aspx">
    <Menu value="Add User" url="~/AddUser.aspx" />


    <div style="padding:10px;">
    <br />

        <asp:TreeView ID="TreeView1" DataSourceID="XmlDataSource1" runat="server">
        <asp:TreeNodeBinding DataMember="Menu" TextField="value" NavigateUrlField="url" />

        <asp:XmlDataSource ID="XmlDataSource1" DataFile="~/Menus.xml" XPath="Menus/Menu" runat="server"></asp:XmlDataSource>

                <asp:ContentPlaceHolder ID="ContentPlaceHolder1"  runat="server">                       


This article will have the code for implementation for treeview control in master page.

1 comment: