Monday 30 July 2012

ASP.NET TreeView Control | TreeView Control,SiteMapDataSource Control in ASP.NET | TreeView Control Example in ASP.NET

                         Hi Friends, I already explained some topics in the ASP.NET ,in this article I will explain about the TreeView Control,SiteMapDataSource Control  in ASP.NET
  • TreeView Control is introduced in ASP.NET 2.0.
  • TreeView is used to display hierarchical data.
  • For example, you can use this control when displaying a navigation menu, displaying database records from database tables in a Master/Detail relation, displaying the contents of an XML document, or displaying files and folders from the file system. It is also possible for you to programmatically access the TreeView object model to dynamically create trees, populate nodes, set properties and so on. The TreeView control consists of nodes and there are three types of nodes that you can add to a TreeView control.
Root - A root node is a node that has no parent node. It has one or more child nodes.
Parent - A node that has a parent node and one or more child nodes
Leaf - A node that has no child nodes.

Let I will explain TreeView Control by using an example.
First of all take one. SiteMap file.
                                      Create one new ASP.NET website.After that Add new Item, select SiteMap  and click OK then web.sitemap file is creted.In the web.sitemap file write the following code.

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
  <siteMapNode title="Home" url="http://aspdotnet-kishore.blogspot.in" >
    <siteMapNode title="ASP.NET"
    url="http://aspdotnet-kishore.blogspot.in/search/label/ASP.NET">
      <siteMapNode title="Send mail"
      url="http://aspdotnet-kishore.blogspot.in/2012/07/how-to-send-mail-through-aspnet-using-c.html"/>
      <siteMapNode title="Introduction to Validation controls"
      url="http://aspdotnet-kishore.blogspot.in/2012/07/aspnet-validation-controls-with-example_24.html"/>
      </siteMapNode>
      <siteMapNode title="VB.NET"
      url="http://aspdotnet-kishore.blogspot.in/search/label/VB.NET">
        <siteMapNode title="How to move the text file or Notepad file "
        url="http://aspdotnet-kishore.blogspot.in/2012/06/how-to-move-text-file-or-notepad-file.html"/>
          <siteMapNode title="Update Panel in AJAX"
          url="http://aspdotnet-kishore.blogspot.in/2012/05/update-panel-in-ajax-ajax-tutorial.html"/>
          </siteMapNode>
 
          </siteMapNode>
        </siteMap>


                                In the above code SiteMap is root tag. SiteMapNode is the Parent node, inside that SiteMapNode are the leaf nodes.
                              Web.sitemap file is created. Let us create a one webForm.Go to the project ,Add New Item select Webform ,name it as aspdotnet-kishore.aspx and click ok then webForm is created.Take one TreeView in navigation parent tag in the ToolBox and SiteMapDataSource in the Data parent tag in the ToolBox and write the following code.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TreeView ID="TreeView1" runat="server" DataSourceID ="SiteMapDataSource1">
        </asp:TreeView>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
    </div>
    </form>
</body>
</html>

When we run the above code then the output will like in the below figure.

ASP.NET TreeView Control | TreeView Control,SiteMapDataSource Control  in ASP.NET | TreeView Control Example in ASP.NET


No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.