<%@ Page language="c#" MasterPageFile="~/SampleCode/SamplesMasterPage.master" Inherits="SmartWebControls.SampleCode.UsingStartNode" CodeFile="UsingStartNode.aspx.cs" %> <%@ Register TagPrefix="swc" Namespace="SmartWebControls" Assembly="SmartWebControls.SmartChart" %> <asp:Content ID="content" runat="server" ContentPlaceHolderID="cphMain"> <div id="divTitle">Using the StartNode Property to Filter Nodes</div> <div id="divInstructions"> SmartChart allows developers to filter nodes using the XPath or StartNode properties. This example demonstrates how the StartNode property can be set programmatically to filter down to a specific employee. This example looks for any Employee nodes with a child id node equal to 304. The XML data used in this example is flat (no hierarchy) so a hierarchy is generated by using the DataSet object combined with the XmlDocument object. </div> <p></p> <asp:Label ID="lblOutput" runat="server" /> <swc:SmartChartPro id="SmartChart1" title="Org Chart" runat="server" OutputType="Html" AllowDrillDown="True" DataTitleFields="name,title" font-size="8" MaxTextLength="30" Width="850px" Height="400px" DataNodeName="Employee" DataKeyField="id" DataFields="name,title" BoxColor="Gainsboro" BoxGradient="True" ChartDepth="2" font-bold="false" MaxChildrenPerLevelGroup="6" HasParentImagePath="~/SampleCode/SmartChartPro/Images/up.gif" HasParentImageVSpace="6" HasChildrenImagePath="~/SampleCode/SmartChartPro/Images/down.gif" HasChildrenImageVSpace="0" DrillDownType="SmartChartImage"></swc:SmartChartPro> <div style="height:400px;"> </div> </asp:Content>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Xml; using System.IO; namespace SmartWebControls.SampleCode { /// <summary> /// Summary description for Employees. /// </summary> public partial class UsingStartNode : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { this.SmartChart1.SmartChartClicking += new EventHandler<SmartChartEventArgs>(this.SmartChart1_SmartChartClicking); if (!Page.IsPostBack) { XmlDocument doc = GetDataSource(); XmlNode node = doc.SelectSingleNode("//Employee[id='304']"); SmartChart1.StartNode = node; SmartChart1.DataSource = doc; SmartChart1.DataBind(); } } private XmlDocument GetDataSource() { //The XML document used here is in a flat scructure (no hierarchy exists) so load it into DataSet //to create relationships DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath("~/SampleCode/SmartChartPro/XML/EmployeesFlatTable.xml")); ds.Tables[0].TableName = "Employee"; DataColumn colParent = ds.Tables[0].Columns["id"]; DataColumn colChild = ds.Tables[0].Columns["pid"]; DataRelation relation = new DataRelation("ParentChildRel",colParent,colChild); relation.Nested = true; ds.Relations.Add(relation); //Loading DataSet directly into an XmlDataDocument constructor can cause an error (object reference error) //when a large number of relationships are present. This is a work around //to that issue. MemoryStream ms = new MemoryStream(); ds.WriteXml(ms); //Write to memorystream ms.Position = 0; XmlDocument doc = new XmlDocument(); doc.Load(ms); //load memorystream into DOM ms.Close(); return doc; } private void SmartChart1_SmartChartClicking(object sender, SmartWebControls.SmartChartEventArgs e) { this.lblOutput.Text = "The item you clicked has an ID of: " + e.Item.DataKey; } } }