Accordion databind to sitemap

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

Chad

Hi

Please Take a look at the following thread :

http://forums.asp.net/t/1375571.aspx

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,
Chad

********Default.aspx********
<%@ 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
	<link href="Accordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<form id="form1" runat="server">
	<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
	</asp:ToolkitScriptManager>
	<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">
		<HeaderTemplate>
			<div class="accordionHeader">
				<a href="<%# Eval("url") %>">
					<%#Eval("title")%></a>
			</div>
		</HeaderTemplate>
		<ContentTemplate>
			<div class="accordionContent">
				<table>
					<asp:Repeater ID="Repeater1" runat="server">
						<ItemTemplate>
							<tr>
								<td id="AccordionSideBarItem">
									<a href="<%# ((System.Web.SiteMapNode)Container.DataItem).Url %>">
										<%# ((System.Web.SiteMapNode)Container.DataItem).Title %></a>
								</td>
							</tr>
						</ItemTemplate>
					</asp:Repeater>
				</table>
			</div>
		</ContentTemplate>
	</asp:Accordion>
	<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
	</form>
</body>
</html>


**********Default.aspx.cs*********


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;
            Accordion1.DataBind();
            }
        }


    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;
                rptr.DataBind();
                }
            }
        }
    }


*********Web.sitemap*********


<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
	<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>


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


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


		<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>


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

 

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?

Chad

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

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,
took
several days,
and I’m a
beginner, thanks
again

Leave a Reply