<%@ Page language="c#" MasterPageFile="~/SampleCode/SamplesMasterPage.master" Inherits="SmartWebControls.SampleCode.UsingXPath" CodeFile="UsingXPath.aspx.cs" %> <%@ Register TagPrefix="swc" Namespace="SmartWebControls" Assembly="SmartWebControls.SmartChart" %> <asp:Content ID="content" runat="server" ContentPlaceHolderID="cphMain"> <div id="divTitle">Using the XPath 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 XPath property can be used with an XPath statement to filter down to a specific employee. The XPath statement looks for any Employee nodes with a child id node equal to 78 (XPath="//Employee[id='78']"). Ancestor nodes of the target node are filtered out completely when using the XPath property. If you're interested in filtering down to a specific node but also allowing the end user to navigate up to an ancestor node use the StartNode property instead. </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="300px" DataNodeName="Employee" DataKeyField="id" DataFields="name,title" BoxColor="Gainsboro" BoxGradient="True" ChartDepth="2" font-bold="false" MaxChildrenPerLevelGroup="6" XPath="//Employee[id='78']" 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 UsingXPath : 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) { SmartChart1.DataSource = GetDataSource(); SmartChart1.DataBind(); } } private DataSet GetDataSource() { 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); return ds; //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; } } }