Try Now

Site Map Control

by Gabe Sumner
Publication date:
Sep 1, 2009, 12:30 PM


  • Sitefinity 3.5

Price: $ 0
On the Sitefinity forums Erik asked how to display an expanded Site Map. Sitefinity includes a "Site Treeview" control that comes close to accomplishing this.  However, this control starts in a "collapsed" state and I have not been able to find a way to easily coax it into an "expanded" state.

The good news is that we can create a Site Map Sitefinity UserControlfairly easily using the RadTreeView.  The control described below simply binds the ASP.NET "SiteMapDataSource" to a RadTreeView control. It then fully expands the RadTreeView.  Here is how this is done:


Step 1: Create the UserControl
Create the following user control file: ~/GoonDocks/UserControls/SiteMap.ascx


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SiteMap.ascx.cs" Inherits="GoonDocks_UserControls_SiteMap" %>  
<%@ Register TagPrefix="rad" Namespace="Telerik.WebControls" Assembly="RadTreeView.NET2" %>  
<rad:radtreeview ID="SiteMapRadTreeView" EnableViewState="false" runat="server" />  


Create the following code-behind file: ~/GoonDocks/UserControls/SiteMap.ascx.cs 


using System;   
using System.Web;   
using System.Web.UI;   
using System.Web.UI.WebControls;   
using System.Web.UI.HtmlControls;   
public partial class GoonDocks_UserControls_SiteMap : System.Web.UI.UserControl   
    protected void Page_Load(object sender, EventArgs e)   
        SiteMapRadTreeView.DataSource = new SiteMapDataSource();   


Step 2: Let Sitefinity know about your new UserControl

In order for Sitefinity to make use of a new UserControl it must declared in the <toolboxControls> section of the "web.config" file.  Add the following line to your "web.config" file:

    <add name="Site Map" section="GoonDocks" url="~/GoonDocks/UserControls/SiteMap.ascx" />     

Step 3: Create a new Sitefinity page and place your "Site Map" control onto the page
There is nothing that you need to edit or configure with this Site Map control.  Just plunk it onto your page and it will do its job.