Accordion databind to sitemap

Is it possible to bind a sitemap to an accordion for a simple menu?



Please Take a look at the following thread :

If This Helps Please Mark as an Answer

Good Luck

Thank you for your response.  The thread you gave me helped me but was coded in VB.  I had to make a few changes for C#.  Below is my working example of an accordion databound to a sitemap in C#.

Thanks again,

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
	<link href="Accordion.css" rel="stylesheet" type="text/css" />
	<form id="form1" runat="server">
	<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
	<asp:Accordion ID="Accordion1" runat="server" SelectedIndex="0" FadeTransitions="true"
		FramesPerSecond="60" TransitionDuration="75" AutoSize="None" RequireOpenedPane="true"
		Width="350px" SuppressHeaderPostbacks="true" HeaderCssClass="AccordionHeaderCssClass"
		HeaderSelectedCssClass="accordionHeaderSelected" OnItemDataBound="Accordion1_DataBound">
			<div class="accordionHeader">
				<a href="<%# Eval("url") %>">
			<div class="accordionContent">
					<asp:Repeater ID="Repeater1" runat="server">
								<td id="AccordionSideBarItem">
									<a href="<%# ((System.Web.SiteMapNode)Container.DataItem).Url %>">
										<%# ((System.Web.SiteMapNode)Container.DataItem).Title %></a>
	<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;

public partial class Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            SiteMapDataSourceView siteMapView = (SiteMapDataSourceView)SiteMapDataSource1.GetView(string.Empty);
            SiteMapNodeCollection nodes = (SiteMapNodeCollection)siteMapView.Select(DataSourceSelectArguments.Empty);
            Accordion1.DataSource = nodes;

    protected void Accordion1_DataBound(object sender, AjaxControlToolkit.AccordionItemEventArgs e)
        if (e.ItemType == AjaxControlToolkit.AccordionItemType.Content)
            AjaxControlToolkit.AccordionContentPanel cPanel = e.AccordionItem;
            System.Web.UI.WebControls.Repeater rptr = (Repeater)cPanel.Controls[1];
            SiteMapNode sNode = (System.Web.SiteMapNode)((AjaxControlToolkit.AccordionItemEventArgs)e).AccordionItem.DataItem;
            System.Web.SiteMapNodeCollection childNodes = sNode.ChildNodes;
            if (childNodes != null && childNodes.Count > 0)
                rptr.DataSourceID = null;
                rptr.DataSource = childNodes;


<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="" >
	<siteMapNode url="~/default.aspx" title="HOME">

		<siteMapNode url="" title="WAYS TO EXPRESS LOVE" description="">
			<siteMapNode url="~/waysToExpressLove.aspx" title="THE FIVE LOVE LANGUAGES" description="" />

		<siteMapNode title="THE LORD'S PRAYER" description="">
			<siteMapNode url="~/expositionOfPsalms23.aspx" title="Exposition of Psalm 23" description="" />

		<siteMapNode title="ABOUT SIN" description="">
			<siteMapNode url="~/aboutSin.aspx" title="Link" description="" />

		<siteMapNode title="ABOUT JESUS CHRIST" description="">
			<siteMapNode url="~/theCrucifixion.aspx" title="The Crucifixion of Jesus Christ" description="" />
			<siteMapNode url="~/theGospel.aspx" title="The Gospel" description="" />

		<siteMapNode title="SPECIAL OFFERS" description="">
			<siteMapNode url="~/trinityLife.aspx" title="Trinity Life Insurance" description="" />
			<siteMapNode url="~/soulSecurity.aspx" title="Soul Security" description="" />


I thought the Ajax Accordion was supposed to keep the viewstate if the header and content templates are used with a data source.  This is not the case for me.  I am using the header and content templates with a data source in a master page and the Accordion
does not keep it’s viewstate.  Does anyone have a suggestion to maintain viewstate?


Took several days
trying to implement a
, connected
to the site map
, will they have an example
handy?, Please,
thank you very much

Llevo varios dias tratando de implementar un acordeón de tres niveles, conectado al mapa del sitio, ¿Tendran un ejemplo a mano?, por favor, de ante mano muchas gracias

Thank you very much
for the reply,
but I can not implement
the three levels, my menu
has the following schema

Item A
     Item A.1
        Item A.1.1
        Item A.1.2
      Item A.2
        Item A.2.1
        Item A.2.2
Item B
      Item B.1
        Item B.1.1
        Item B.1.2
      Item B.2
        Item B.2.1
        Item B.2.2

Item C
     Item C.1
        Item C.1.1
        Item C.1.2
      Item C.2
        Item C.2.1
        Item C.2.2

and I have
implemented a
sitemap AspNetSqlSiteMapProvider
to recover, I’m desperate,
several days,
and I’m a
beginner, thanks

Leave a Reply