SiteMapDataSource Example in ASP.NET using C#

SiteMapDataSource Example in ASP.NET using C#


Posted in : ASP.Net Posted on : December 11, 2010 at 6:03 PM Comments : [ 0 ]

In this article we will introduce with SiteMapDataSource control in ASP.NET using C#.

SiteMapDataSource Example in ASP.NET using C#

The SiteMapDataSource control is a data source control which is used site map data. The Site map is just like an Xml file which is stored the site navigation path. In this example we use a TreeView and provide data using SiteMapDataSource. Now the first thing is How will make Sitemap data. There are following step to make Site Map data.

Step 1. Add web.SiteMap in your project.

Now open your web.SiteMap file and put the following code.

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>

Now Click smart tag button of TreeView and Choose Data Source. Select Map Path and Click OK.

SiteMapDataSource.aspx (Design Page):

SiteMapDataSource.aspx (source code):

<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" 
AutoEventWireup="true"
CodeFile="SiteMapDataSource.aspx.cs" Inherits="SiteMapDataSource" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div>
<h2 style="color: Green">
SiteMapDataSource in ASP.NET 4, C#</h2>
<asp:TreeView ID="TreeView1" runat="server" ImageSet="Simple" 
DataSourceID="SiteMapDataSource1" ShowLines="True" >
<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>
&nbsp;&nbsp;&nbsp;
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
</div>
</asp:Content>

Output:

Download source code
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics