Asp.net organization chart control, asp.net Organization Structure
I remember that when I was working on a project, the customer had to look at an organizational structure chart to get a picture of the company's situation. I had never done this control before, so I had to look for du Niang, out of its perfection in the project, many widgets on the Internet were relatively poor. Later, I had to pick a better one among them. First, let's look at the figure:
First:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "inherit" Inherits = "OrgCharts_asp_Demo" %> <% @ Register Assembly = "bporgdi#" Namespace =" BasicPrimitives. orgdi#" TagPrefix = "PC3" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html xmlns =" http://www.w3.org/1999/xhtml "> <Head runat =" server "> <title> </title> <script type =" text/javascript "src = ".. /Scripts/jquery-1.9.1.js "> </script> <script type =" text/javascript "src = ".. /Scripts/jquery-ui-1.10.2.custom.min.js "> </script> <script type =" text/javascript "src = ".. /Scripts/json3.min. js "> </script> <link rel =" stylesheet "type =" text/css "href = ".. /Scripts/ui-lightness/jquery-ui-1.10.2.custom.min.css "/> <link href = ".. /Scripts /Primitives.latest.css "rel =" stylesheet "/> <script type =" text/javascript "src =" ../Scripts/primitives. min. js? 204 "> </script> <style type =" text/css "> # Form {width: 100% ;} </style>
Background implementation:
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; using BasicPrimitives. orgdiing; using System. drawing; using BasicPrimitivesDemo; using System. data; using CAF. DBUtility; using Microsoft. office. interop. excel; public partial class OrgCharts_asp_Demo: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {// Only bind the data on the first page load... only bind the data on the first page to load... If (! Page. isPostBack) {GetData () ;}} protected void orgDiagram_SelectedItemChanged (object sender, EventArgs e) {Item selectedItem = this. orgdi. selectedItem;} protected void orgDiagram_ItemCheckChanged (object sender, EventArgs e) {Items checkedItems = this. orgdi. checkedItems ;} /// <summary> /// event triggered by clicking the button at the edge of the box /// </summary> /// <param name = "sender"> </param>/ // <param name = "e"> </param> prot Ected void orgDiagram_TemplateButtonClick (object sender, TemplateButtonClickEventArgs e) {String buttonName = e. buttonName; // The Name Of The three buttons Item clickedButtonItem = e. item; string p_id = clickedButtonItem. value; if (buttonName = "Export EXCEL as the parent node") {// Excel_Out (p_id); // SetRangeBackground (4, 2, 6, 4, 003366 );} else if (buttonName = "Expand" & p_id! = "01") {AddOrg (clickedButtonItem, clickedButtonItem. value) ;}/// <summary> // obtain Data /// </summary> private void GetData () {this. orgdi. items. clear ();
DataSet ds = CAF. DBUtility. SqlHelper. ExecuteDataSet (""); // Data Source
This. viewState ["ds"] = ds;/* Root */Item MarkKornegay = new Item ("Group", "01", "GM Group ",".. /images/photos/a.png "); MarkKornegay. templateName = "UserTemplateContact"; MarkKornegay. titleColor = Color. cornflowerBlue; // MarkKornegay. groupTitle = "Group"; // MarkKornegay. groupTitleColor = Color. blue; MarkKornegay. showCheckBox = BasicPrimitives. orgdi. enabled. false; MarkKornegay. showButtons = Basic Primitives. orgdi. enabled. true; this. orgdi. items. add (MarkKornegay); AddOrg (MarkKornegay, "01 ");} /// <summary> /// append node /// </summary> /// <param name = "P_Org_Item"> </param> /// <param name = "int_parent_id"> </param> public void AddOrg (Item P_Org_Item, string int_parent_id) {string id = ""; string name = ""; string parent_org_id = ""; string org_type = ""; DataSet ds = (DataSet) this. viewSt Ate ["ds"]; DataRow [] dr = ds. tables [0]. select ("parent_org_id = '" + int_parent_id + "'"); foreach (DataRow dr1 in dr) {id = dr1 ["id"]. toString (); name = dr1 ["name"]. toString (); parent_org_id = dr1 ["parent_org_id"]. toString (); org_type = dr1 ["org_type"]. toString (); Item demo_item = new Item (name, id, "test ",".. /images/photos/a.png "); if (id. length! = 11) {demo_item.TemplateName = "UserTemplateContact";} demo_item.TitleColor = Color. cornflowerBlue; // demo_item.GroupTitle = "Group"; // demo_item.GroupTitleColor = Color. orange; demo_item.ShowCheckBox = BasicPrimitives. orgdi. enabled. false; demo_item.ShowButtons = BasicPrimitives. orgdi. enabled. true; P_Org_Item.Items.Add (demo_item); // AddOrg (demo_item, id );}}}