Friday, 11 May 2012

how to use SiteMapPath control in asp.net

SiteMapPath is a Navigation ToolBox Control. Here i show a simple example of SiteMapPath control.

Web.sitemap
First we need to create a Web.sitemap file. Here is the source code of Web.sitemap file.


  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >  
  3.   <siteMapNode url="Default.aspx" title="Home"  description="Home Page">  
  4.     <siteMapNode url="StandardToolBox.aspx" title="Standard ToolBox Control"  description="Standard ToolBox Control">  
  5.       <siteMapNode url="BulletedList.aspx" title="BulltedList Example"  description="BulltedList Control Simple Example" />  
  6.       <siteMapNode url="CheckBox.aspx" title="CheckBox Example"  description="CheckBox Control Simple Example" />  
  7.       <siteMapNode url="CheckBoxList.aspx" title="CheckBoxList Example"  description="CheckBoxList Control Simple Example" />  
  8.       <siteMapNode url="Image.aspx" title="Image Control Example" description="Image Control Simple Example"/>  
  9.     </siteMapNode>  
  10.     <siteMapNode url="DataToolBox.aspx" title="Data ToolBox Control"  description="Data ToolBox Control">  
  11.       <siteMapNode url="SqlDataSource.aspx" title="SqlDataSource Example"  description="SqlDataSource Simple Example" />  
  12.       <siteMapNode url="XmlDataSource.aspx" title="XmlDataSource Example"  description="XmlDataSource Simple Example" />  
  13.     </siteMapNode>  
  14.   </siteMapNode>  
  15. </siteMap>  
SiteMapPath Control
Now create a simple WebForm name Image.aspx. Then place a SiteMapDataSource control and a SiteMapPath control. When you run this Image.aspx page, you can see the location of Image.aspx file in your navigation system. Here is the source code of Image.aspx file.

  1. <%@ Page Language="C#" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.   
  5. <script runat="server">  
  6.   
  7. </script>  
  8.   
  9. <html xmlns="http://www.w3.org/1999/xhtml">  
  10. <head runat="server">  
  11.     <title>SiteMapPath Control Simple Example</title>  
  12. </head>  
  13. <body>  
  14.     <form id="form1" runat="server">  
  15.     <div>  
  16.         <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />  
  17.         <asp:SiteMapPath ID="SiteMapPath1" runat="server"></asp:SiteMapPath>  
  18.         <br /><br />  
  19.         <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/SeaBeach.jpg" Height="300" Width="400" />  
  20.     </div>  
  21.     </form>  
  22. </body>  
  23. </html>  




2 comments:

  1. Do not take it easy.I have got your address from your blog.Then its easy for me to give a case in police station against you.your all article copied from code project or different Blogs.You have five day in your hand delete your blog or delete all content otherwise you have to penalized to jail and your carrier may be stop.Be serious and delete it as soon as possible.Scott Microsoft Team Member

    ReplyDelete
  2. Hey what is this you are not delete my content till now.its my final warning to you delete all post and dont copy from any body.

    ReplyDelete