Saving data by handling the SmartChartSaving event.
SmartChart provides a rich event model that allows developers to know when changes have been made to a chart. This example demonstrates how the SmartChartSaving event can be handled to save any end user modifications. To try the demo, edit an SmartChart item by mousing over the desired item and selecting Edit from the menu. Once changes have been made click Save (located immediately above the chart).

Save
Save Event Demo
-
Lin Thomas
CIO




-
-
Patti Bell
Admin Assistant
Paul Johnson
Deputy CIO





-
-
-
Greg Jamison
Web Mgr
Jack Doe
PC Mgr
Troy Wallace
Exchange

















-
-
Terri James
Developer
Brian Gain
Developer
-
-
-
John
Developer
Dave
Developer
Rene
Developer
-
-
John
Architect
Tommy
Systems












-
-
Dave Davies
DBA Mgr
Tom Davies
Dev Mgr
-
Jimmy Jones
Developer
-
-
-
John
Designer
Tommy
Developer
Tommy
DBA
 
ASPX Code

<%@ Page Language="C#" MasterPageFile="~/SampleCode/SamplesMasterPage.master" AutoEventWireup="true" CodeFile="SaveEventDemo.aspx.cs" Inherits="SampleCode_SmartChartEvents_SaveEventDemo" %>
<%@ Register TagPrefix="swc" Namespace="SmartWebControls" Assembly="SmartWebControls.SmartChart" %>
<asp:Content ID="content" runat="server" ContentPlaceHolderID="cphMain">
    <br />
    <div id="divTitle">
        Saving data by handling the SmartChartSaving event.</div>
    <div id="divInstructions">
        SmartChart provides a rich event model that allows developers to know when changes have been made to a chart.  This example demonstrates
        how the SmartChartSaving event can be handled to save any end user modifications.  To try the demo, edit an SmartChart item by mousing over the desired
        item and selecting Edit from the menu.  Once changes have been made click Save (located immediately above the chart).
    </div>
    <p></p>
    <swc:SmartChartPro ID="SmartChart1" Title="Save Event Demo" runat="server"
        ShowToolbar="True" ShadowColor="LightGray"
        Font-Names="Verdana" Font-Bold="True" RoundBoxEdgesAmount="10" OutputType="Html"
        Height="472px" Width="750px" ImageWidth="90" ImageHeight="70" TitleColor="MidnightBlue"
        ShadowOffset="5" AllowDrillDown="True" BoxTextColor="Black" BoxColor="LightGray"
        MaxTextLength="25" DataFields="name,title,contact" DataKeyField="id" DataNodeName="person"
        DataTitleFields="name,desc,contact" BackgroundImage="" DrawShadows="True" HighlightChildrenOnMouseOver="True"
        ToolbarCssClass="toolbar" HasParentImagePath="~/SampleCode/SmartChartPro/Images/up.gif"
        HasChildrenImagePath="~/SampleCode/SmartChartPro/Images/down.gif" DrillDownType="SmartChartImage"
        HasChildrenImageVSpace="2" HasParentImageVSpace="10" ChartDepth="5" BoxGradient="True" 
        AllowEditing="True">
    </swc:SmartChartPro>
    &nbsp;
    <asp:Panel ID="pnlSave" runat="server" Visible="False">
        <b>SmartChart data saved (see save event handler in code-behind file).</b>    
        <br />
        <asp:TextBox ID="txtSave" runat="server" TextMode="MultiLine" Rows="25" 
        Columns="60" style="width:98%;" />

    </asp:Panel>
</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;
using System.Drawing;
using SmartWebControls;

public partial class SampleCode_SmartChartEvents_SaveEventDemo : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.SmartChart1.SmartChartDeleting += new EventHandler<SmartChartEventArgs>(this.SmartChart1_SmartChartDeleting);
        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.Black;
            }
            if (title.IndexOf("developer") != -1)
            { //Found a node that has what we want
                item.BackColor = Color.Firebrick;
                item.ForeColor = Color.White;
            }
        }
    }

    private void SmartChart1_SmartChartSaving(object sender, SmartWebControls.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);
        using (System.IO.StringWriter sw = new System.IO.StringWriter())
        {
            XmlWriterSettings ws = new XmlWriterSettings();
            ws.Indent = true;
            using (XmlWriter writer = XmlWriter.Create(sw,ws))
            {
                doc.WriteContentTo(writer);
            }
            this.txtSave.Text = sw.ToString();
        }
    }

    private void SmartChart1_SmartChartDeleting(object sender, SmartWebControls.SmartChartEventArgs e)
    {

    }

}