-->

22 December 2019

Asp.net Hierarchical DataBound Controls

  Asp.Net CS By Example       22 December 2019


 Hierarchical DataBound Controls:  

  A hierarchical DataBound control can display nested data items. For example, we can use
hierarchical DataBound controls to display the folder and page structure of our website,
the contents of an XML file, or a set of master/detail database records.

The ASP.NET includes two hierarchical DataBound controls:
1) Menu—Displays data items in a static or dynamic menu.
2) TreeView—Displays data items in a tree.

 The Menu and TreeView controls are bound to an XmlDataSource control,
which represents the XML file.

  Code: HierarchicalDataBoundEx01.aspx 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HierarchicalDataBoundEx01.aspx.cs"
    Inherits="LearnAsp.Net.ControlDemo.DataBound.HierarchicalDataBoundEx01" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Hierarchical Databound Controls</title>
    <style type="text/css">
        .floater
        {
            float: left;
            border: solid 1px black;
            padding: 5px;
            margin: 5px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="floater">
        <h3>
            TreeView</h3>
        <asp:TreeView ID="CheckBoxList1" DataSourceID="srcMovies" runat="server" />
    </div>
    <div class="floater">
        <h3>
            Menu</h3>
        <asp:Menu ID="BulletedList1" DataSourceID="srcMovies" runat="server" />
    </div>
    <asp:XmlDataSource ID="srcMovies" DataFile="Movies.xml" XPath="movies/*" runat="server" />
    </form>
</body>
</html>


  Code: Movies.xml 
<?xml version="1.0" encoding="utf-8" ?>
<movies>
  <Adventure>
    <StarWars />
    <JurassicPark />
    <IndependenceDay />
  </Adventure>
  <Animation>
    <IceAge />
    <Shrek />
  </Animation>
  <Drama>
    <Titanic />
    <Ghost />
    <ForrestGump />
  </Drama>
  <Horror>
    <Jaws />
    <TheRing />
  </Horror>
</movies>

  Output:

logoblog

Thanks for reading Asp.net Hierarchical DataBound Controls

Previous
« Prev Post

No comments:

Post a Comment

Please do not enter any spam link in the comment box.