ASPX Code
<%@ Page Language="C#" MasterPageFile="~/SampleCode/SamplesMasterPage.master" AutoEventWireup="true" CodeFile="CustomSiteMap.aspx.cs" Inherits="SampleCode_DataSources_CustomSiteMap" Title="SmartChart - http://www.xmlforasp.net" %>
<%@ Register Assembly="SmartWebControls.SmartChart" namespace="SmartWebControls" tagprefix="swc" %>
<asp:Content ID="content" runat="server" ContentPlaceHolderID="cphMain">
<div id="divTitle">Binding web.sitemap to the SmartChart control</div>
<div id="divInstructions">
SmartChart allows sitemap files to be bound to the control.
Custom images can be supplied to enhance the output as shown here.
Images paths located in the web.sitemap file are identified by using the
SmartChart control's ImageField property. The height and width of the image
are defined using the control's ImageWidth and ImageHeight properties.
</div>
<p />
<swc:SmartChartPro id="SmartChart1" title="Custom Sitemap Demo" DataSourceID="smDS"
runat="server" ShadowColor="LightGray"
Font-Names="Verdana" Font-Bold="True" Drawborder="false"
OutputType="Html" Height="300px" Width="850px"
ImageWidth="48" ImageHeight="48"
TitleColor="MidnightBlue" ShadowOffset="5" FontStyle="Bold" AllowDrillDown="True"
BoxTextColor="Navy" BoxGradient="True" BoxColor="Lavender" MaxTextLength="25"
DataFields="title" ImageField="image" DataNodeName="siteMapNode" DataTitleFields="url"
DrawShadows="True" HighlightChildrenOnMouseOver="True"
DrillDownType="SmartChartItem"
ChartDepth="2" MaxChildrenPerLevelGroup="8"
BoxBorderColor="Black" TextOnly="True" HasParentImageVSpace="0"
onSmartChartclicked="SmartChart1_SmartChartClicked" BackColor="White" />
<asp:SiteMapDataSource ID="smDS" runat="server" />
</asp:Content>
C# Code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
public partial class SampleCode_DataSources_CustomSiteMap : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SmartChart1_SmartChartClicked(object sender, SmartWebControls.SmartChartEventArgs e)
{
XmlDocument doc = (XmlDocument)SmartChart1.DataSource;
//__Key represents the auto-generated unique key for a node
//It's added by the control in cases where the XML source doesn't not include unique identifiers
XmlNode node = doc.SelectSingleNode("//siteMapNode[@__Key='" + e.Item.DataKey + "']");
if (node != null)
{
XmlAttribute url = node.Attributes["url"];
if (url != null && !String.IsNullOrEmpty(url.Value)) Response.Redirect(url.Value);
}
}
}