In this article we will introduce with the TreeView control in ASP.NET using C#.
TreeView Example in ASP.NET using C#
TreeView control in ASP.NET is used Navigation. TreeView control is a Navigation control. It supports a variety of programming models, from statically-defined trees, to dynamically constructed trees, to databound trees. You can bound the data with TreeView control by using SiteMapDataSource or XMLDataSource. It is rendered a tree view UI. In this example we use the SiteMapDataSource for bind the data with TreeView. You can see the following how can I use the AutoFormat for TreeView.
TreeView.aspx (Design Page):
Web.sitemap file:
<?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="http://www.devmanuals.com/" title="ASP.NET" description="ASP.NET Tutorials"> <siteMapNode url="http://www.devmanuals.com/tutorials/ms/aspdotnet/index.html" title="Controls" description="Standards Controls"> <siteMapNode url="~/TextBox.aspx" title="TextBox" description="TextBox Control"/> <siteMapNode url="~/BulletList.aspx" title="BulletList" description="BulletList Control"/> <siteMapNode url="~/Image.aspx" title="Image" description="Image Control"/> <siteMapNode url="~/ImageMap.aspx" title="ImageMap" description="ImageMap Control"/> </siteMapNode> <siteMapNode url="http://www.devmanuals.com/tutorials/ms/aspdotnet/requiredfieldvalidator.html" title="Validator" description="Validation Controls"> <siteMapNode url="~/RequiredFieldValidator.aspx" title="RequiredFieldValidator" description="RequiredFieldValidator"/> <siteMapNode url="~/CompareValidator.aspx" title="CompareValidator" description="CompareValidator"/> <siteMapNode url="~/RangeValidator.aspx" title="RangeValidator" description="RangeValidator"/> <siteMapNode url="~/RegularExpressionValidator.aspx" title="RegularExpressionValidator" description="RegularExpressionValidator"/> <siteMapNode url="~/CustomValidator.aspx" title="CustomValidator" description="CustomValidator"/> <siteMapNode url="~/ValidationSummary.aspx" title="ValidationSummary" description="ValidationSummary"/> </siteMapNode> </siteMapNode> </siteMap>
TreeView.aspx (source code):
<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" AutoEventWireup="true" CodeFile="TreeView.aspx.cs" Inherits="TreeView" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div> <h2 style="color: Green"> TreeView in ASP.NET 4, C#</h2> <asp:TreeView ID="TreeView1" runat="server" ImageSet="Simple" DataSourceID="SiteMapDataSource1"> <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" /> <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="0px" NodeSpacing="0px" VerticalPadding="0px" /> <ParentNodeStyle Font-Bold="False" ImageUrl="~/Images/bullet-red.png" /> <RootNodeStyle ImageUrl="~/Images/bullet.png" /> <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" /> </asp:TreeView> <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" /> <br /> </div> </asp:Content>
[ 0 ] Comments