<%@ Page MasterPageFile="~/SampleCode/SamplesMasterPage.master" language="c#" Inherits="SmartWebControls.SampleCode.DragDropEdit" CodeFile="DragDropEdit.aspx.cs" %> <%@ Register TagPrefix="swc" Namespace="SmartWebControls" Assembly="SmartWebControls.SmartChart" %> <asp:Content ID="content" runat="server" ContentPlaceHolderID="cphMain"> <div id="divTitle">Editing, Dragging and Dropping</div> <div id="divInstructions"> SmartChart allows items to be edited as well as dragged and dropped to different locations. Editing is enabled by setting the AllowEditing property to True while drag and drop is enabled by setting the AllowDragDrop property to True. Experiment with these features by mousing over an SmartChart item and clicking the Edit menu to edit an item or hold down the mouse while over an item to drag it to another location on the chart. </div> <p /> <swc:SmartChartPro id="SmartChart1" title="SmartChartRectangleRender Event Demo" runat="server" ShowToolbar="True" AllowEditing="True" AllowDragDrop="True" ShadowColor="LightGray" Font-Names="Verdana" Font-Bold="True" RoundBoxEdgesAmount="10" OutputType="Html" Height="472px" Width="850px" ImageWidth="90" ImageHeight="70" TitleColor="MidnightBlue" ShadowOffset="5" FontStyle="Bold" AllowDrillDown="True" BoxTextColor="Navy" BoxGradient="True" BoxColor="LightGray" MaxTextLength="25" DataFields="name,title,contact" DataKeyField="id" DataNodeName="person" DataTitleFields="name,desc,contact" BackgroundImage="" DrawShadows="True" HighlightChildrenOnMouseOver="True" ToolbarCssClass="toolbar" HasParentImagePath="../Images/up.gif" HasChildrenImagePath="../Images/down.gif" DrillDownType="SmartChartImage" HasChildrenImageVSpace="0" HasParentImageVSpace="8" ChartDepth="5" MaxChildrenPerLevelGroup="8" ScrollContainerHeight="0px" ScrollContainerWidth="0px"></swc:SmartChartPro> <asp:Panel ID="pnlSave" Runat="server" Visible="False"> <B>SmartChart data saved (see save event handler in code-behind file).</B> </asp:Panel> </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.Drawing.Drawing2D; namespace SmartWebControls.SampleCode { /// <summary> /// Summary description for OrgsTest. /// </summary> public partial class DragDropEdit : System.Web.UI.Page { protected override void OnInit(EventArgs e) { base.OnInit(e); this.SmartChart1.SmartChartSaving += new EventHandler<SmartChartSaveEventArgs>(this.SmartChart1_SmartChartSaving); this.SmartChart1.SmartChartRectangleRendering += new EventHandler<SmartChartEventArgs>(this.SmartChart1_SmartChartRectangleRendering); } protected void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { string xmlPath = Server.MapPath("~/SampleCode/SmartChartPro/XML/OrgChart.xml"); XmlDocument doc = new XmlDocument(); doc.Load(xmlPath); //Hook up event to event handler SmartChart1.DataSource = doc; SmartChart1.DataBind(); } } /// <summary> /// Before the SmartChart renders the chart demonstrate how to change the background. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SmartChart1_SmartChartRectangleRendering(object sender, SmartWebControls.SmartChartEventArgs e) { if (e.Item.DataItem != null) { SmartWebControls.SmartChartItem item = e.Item; Color boxColor = Color.Empty; //Grab appropriate title key from DataKeyField values and use it to access the text value string title = item.DataItem["title"].ToString().ToLower(); if (title.IndexOf("mgr") != -1) { //Found a node that has what we want item.BackColor = Color.ForestGreen; item.ForeColor = Color.White; } if (title.IndexOf("developer") != -1) { //Found a node that has what we want item.ForeColor = Color.White; item.BackColor = Color.Firebrick; } if (title.IndexOf("admin") != -1) { item.DrawBorder = false; item.BackColor = Color.White; item.ForeColor = Color.Black; item.DrawShadows = false; } } } private void SmartChart1_SmartChartSaving(object sender, SmartChartSaveEventArgs e) { //Save data back to database or else where this.SmartChart1.Visible = false; this.pnlSave.Visible = true; XmlDocument doc = (XmlDocument)e.Result; //Save doc.... doc.Save(path); } } }