• Articles
  • Buy Now
  • Back to Orgchartcomponent.com
  • View Demo:

Demo 1 ASP.NET Org Chart Component - Displaying an Org Chart

This simple demonstration shows an XML Organisation Chart Component using the HtmlTemplate property. The chart is bound this XML file of 9 items.

The HtmlTemplate property is available on each 5 different chart items ( Chart, Assistant, Stack, Edit and Summary ) and it takes Html and substitutes {field Name} for each item where field Name is the name of an attribute within an XML document or a column name within a datatable.

Change the HtmlTemplate using the drop down box below to change the chart. The HtmlTemplate property provides a quick and simple method of formatting organisation charts and can be used when you have simple formating requirements.

Smith
Pinter
Hindes
Green
Klien
Boston
York
Tunbridge
Mustard

{name}

CodeCode

C# Code

1:   protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
2:     {
3:        
4:         
5:         // User has
            changed the drop down list, so update the orgchart template
6:         switch (DropDownList1.SelectedValue)
7:         {
8:             case "1": XmlOrgChart.ChartItem.HtmlTemplate = @"{name}";
9:                 break;
10:             case "2": XmlOrgChart.ChartItem.HtmlTemplate = @"{name},{Firstname}<br/>
                <B>{JobTitle}</B>";
11:                 break;
12:             case "3": XmlOrgChart.ChartItem.HtmlTemplate 
13:                     = 
            @"<TABLE class='demo1' align='center'><TR><TD align=center ><TABLE><TR><TD>Name:</TD><TD>{Firstname}
            {name}</TD></TR><TR><TD>Job title:</TD><TD><B>{JobTitle}</B></TD></TR></TABLE></TD></TR></TABLE>";
14:                 break;
15:  
16:             default: XmlOrgChart.ChartItem.HtmlTemplate = @"<TABLE class='demo1' align='center'><TR><TD align=center>{name}</TD></TR></TABLE>";
17:                 break;
18:         }
19:  
20:         
21:         lblHtmlTemplate.Text = Server.HtmlEncode(XmlOrgChart.ChartItem.HtmlTemplate);
22:         // If the user has selected
            option 3 then do not show the background image
23:         XmlOrgChart.ChartItem.ShowBackgroundImage = DropDownList1.SelectedIndex != 2;
24:  
25:         // Display
            the chart
26:         XmlOrgChart.DataBind();
27:     }

Html Markup

   1:  <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/data1.xml"></asp:XmlDataSource>
   2:      <table>        
   3:          <tr>
   4:              <td valign="top">
   5:                  <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
   6:                      <asp:ListItem Value="1">Example 1 - Simple</asp:ListItem>
   7:                      <asp:ListItem Value="2">Example 2 - Two Fields</asp:ListItem>
   8:                      <asp:ListItem Value="3">Example 3 - More Complex</asp:ListItem>
   9:                  </asp:DropDownList>
  10:                  <br />
  11:                  <asp:Label ID="lblHtmlTemplate" runat="server" Text="TextBox1" BorderColor="Black"
  12:                      BorderWidth="1px" Height="150px" Width="350px"></asp:Label>
  13:              </td>
  14:              <td valign="top">
  15:                  <cc1:XmlBoundOrganisationChart ID="XmlOrgChart" DataSourceID="XmlDataSource1" runat="server">
  16:                      <ChartItem Colour="Grey" HtmlTemplate="{name}">
  17:                      </ChartItem>
  18:                  </cc1:XmlBoundOrganisationChart>
  19:              </td>
  20:          </tr>
  21:      </table>

Valid XHTML 1.0 Transitional Valid CSS!