Onlineatoz.net | ToolBox Data Control SiteMapDataSource

ToolBox Data Control SiteMapDataSource

SiteMapDataSource Web Server Control

in ASP.NET environment,This article describes you how to work with SiteMapDataSource Web Control.Normally, The SiteMapDataSource control can be used to represent the navigation path such as one to another page. The SiteMapDataSource Web server control retrieves navigation data from a site-map provider, and then passes the data to controls that can display that data, such as the TreeView and Menu controls.

This data includes information about the pages in your Web site, such as the URL, title, description, and location in the navigation hierarchy. Storing your navigation data in one place makes it easier to add and remove items in the navigational menus of your Web site.

Display Site-Map Data in Non-Hierarchical Web Server Controls

in DOT.Net environment,we are able to bind site-map data to non-hierarchical controls, such as the DropDownList, CheckBoxList that display data in a linear, or flat, format. Site-map data is inherently hierarchical, which means that each node can contain zero or more child nodes. The TreeView and Menu controls are designed to work with hierarchical data.

The following code snippets shows an DropDownList control to display the site-map data from a Web.sitemap file.

in .aspx.cs file

Public void _OnSelectedIndexChanged(ByVal Sender As Object, ByVal e As EventArgs)
    Response.Redirect(ddl1.SelectedItem.Value)
  End Sub

in .aspx file,

<body>
    <form id="form2" runat="server">
    <div>
      <asp:SiteMapDataSource ID="SMS1" Runat="Server"
          StartFromCurrentNode="true"
          ShowStartingNode="false" />
      <asp:DropDownList ID="ddl1" Runat="Server" 
          DataSourceID="SMS1"
          AutoPostBack="True" 
          DataTextField="Title" 
          DataValueField="Url"
          OnSelectedIndexChanged="_OnSelectedIndexChanged" >
      </asp:DropDownList>
    </div>
    </form>
</body>
                   
                    
 
Add Simple Site Navigation

By Using SiteMapPath, TreeView, or Menu controls, users can easily understand the navigation path of your Web site. A Simple Navigation path of SiteMapPath looks like as:

Home > Profile > Contact

To create a Web.sitemap file
  • Create a file in the root directory of your Web site called Web.sitemap.
  • Open the Web.sitemap file and add the following code.
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
  <siteMapNode title="Home" >
    <siteMapNode title="Profile" >
      <siteMapNode title="Contact" url="~/Contact.aspx"/>
    </siteMapNode>
  </siteMapNode>
</siteMap>           
                    
  • Save your file and then close it.
To add site navigation to a Web page
  • Create a file in the root directory of your Web site called Training.aspx.
  • Open Training.aspx and add the following code.
<html  >
<head id="Head1" runat="server">
  <title>Example Navigation</title>
</head>
<body>
  <form id="form2" runat="server">
  <div>

  <h2>Using SiteMapPath</h2>
  <asp:SiteMapPath ID="SMP1" Runat="server">
  </asp:SiteMapPath>


  <asp:SiteMapDataSource ID="SMS1" Runat="server" />

  <h2>Using TreeView</h2>
  <asp:TreeView ID="Tree1" Runat="Server" DataSourceID="SMS1">
  </asp:TreeView>

  <h2>Using Menu</h2>
  <asp:Menu ID="Menu2" Runat="server" DataSourceID="SMS1">
  </asp:Menu>
  
  <h2>Using a Horizontal Menu</h2>
  <asp:Menu ID="Menu1" Runat="server" DataSourceID="SMS1"
    Orientation="Horizontal" 
    StaticDisplayLevels="2" >
  </asp:Menu>
  
  </div>
  </form>
</body>
</html>                 
                    
  • Save and close the file.now you run and make sure the output.

Posted by: Admin
Posted on: 9/13/2011 at 7:27 PM
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed