ASP tutorial. NET Datagridtree down-pull tree implementation method
The principle of the down-pull tree output JSON to client client to implement dynamic loading the middle will not and server-side interaction data support on the test thousands of or very soon the dropdown tree control is implemented with the C#+js tree
--------------------------------------------------------------------------------
2.c# Calculator Compute string Mathematical expression source code
It is practical to use C # to realize the mathematical expression principle of computation
A. Build two stacks: first bit operand stack, second operation Fu Fu! (defines the stack as a string type)
B. The number is unconditionally pressed into the digital stack.
C. While for symbols, only the current top of the stack element is less than the priority of the scan to the symbol (such as "+" less than "*"), the symbol is pushed into the stack, otherwise greater than or equal to the current stack top element pop-up stack, The first two digits of the current digital stack are calculated. The result is used as a number into the digital stack as the top of the stack (to discard the two digits that have popped up), and the scanned symbol will replace the pop-up symbol as the top element of the stack.
D. The last parenthesis, the principle is to scan to the left parenthesis unconditionally pressed into the symbol stack, while sweeping to the closing parenthesis, then pop off the top of the stack of the most recent left parenthesis above the number of symbols and digital stack to do the operation
--------------------------------------------------------------------------------
3.asp.net Tutorial Datagridtree Table tree controls
inherit a table tree control implemented by the DataGrid control
/* Table Tree Control Description
* This control inherits the DataGrid new Property Description:
* 1.treeparentcode: Top-level root node parentcode
* 2.treedisplaydeep: Show Table Tree depth defaults to 1
* 3.sumcolumns: The collection of fields that are automatically rolled up to the root node is for Decimal Type
* 4. New Tree column Template Templatetreecolumn This template inherits TemplateColumn overrides method InitializeCell
* Client new feature configuration Description
* 1. Fixed column configuration it Emstyle-css Tutorial class= ' Tdlockedclass '
* 2. Fixed header configuration headerstyle-cssclass= ' Trlockedclass '
* 3. Text box input or <asp: TextBox configuration Event onchange= ' sumparent (this); ' The number changes accordingly all the parent nodes are not supported with the change for numeric type other
* But can customize JS
* Report Description:
* 1.datagridtree.en Ableviewstate=false; increase loading Speed
* 2. Dynamically define column implementation BoundColumn column = new BoundColumn ();
Column.headertext = dynamic column;
Col Umn.datafield = "Unitname";
Datagridnew.columns.add (column);
* You can also customize the default template dynamic load template definition Template example Templatetreecolumn, do not inherit TemplateColumn, implement Interface ITemplate InitializeCell method is OK
* Deficiencies: 1. Do not know how to implement
* 2 for complex multiple-row headers. When the amount of data in the table header and column is large, it will affect the amount of data that reflects the speed of about 1000. The amount of data in the big words class consider using AJAX dynamic load currently this feature is not implemented
Instance Code
private void Maketree (DataTable dtnodesets, String Strparentcolumn, String strrootvalue, String strindexcolumn, String St Rtextcolumn, DropDownList drpbind, int i)
{
One more indent unit per layer down
i++;
DataView dvnodesets = new DataView (dtnodesets);
Dvnodesets.rowfilter = strparentcolumn + "=" + Strrootvalue;
String strpading = ""; Indent characters
by I to control the length of the indented character, I'm setting a full-width space here.
for (int j = 0; J < i; J + +)
Strpading + = ""; If you want to increase the length of the indentation, change it to two full-width spaces.
foreach (DataRowView drv in dvnodesets)
{
TreeNode Tnnode = new TreeNode ();
ListItem li = new ListItem (strpading + "├" + drv[strtextcolumn].tostring (), drv[strindexcolumn].tostring ());
Drpbind.items.add (LI);
Maketree (Dtnodesets, Strparentcolumn, drv[strindexcolumn].tostring (), Strindexcolumn, Strtextcolumn, Drpbind, i);
}
Recursive end, to go back to the previous layer, so the indent amount is reduced by one unit
i--;
}
<summary>
SQL statement query, then bind to droplist inside
</summary>
private void Createtree ()
{
Query Zonelist
String sql = "SELECT * from Master_department where parent_department= ' 003 '";
DataSet ds = Db.getds ();
DataTable dt = ds.tables[0];
Maketree (DT, "Parent_department", "003", "Department_code", "Department_name", DropDownList1,-1);
}
Another good example to find on the Internet
using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Web.UI.WebControls;
Namespace Interface.common
{
public interface Idropdowntree:idisposable
{
/**////<summary>
Return dictionary ID, text, if no child node returns null
</summary>
<param name= "ParentID" > Parent node id</param>
<returns></returns>
Dictionary<string, string> getchildcategory (string parentid);
/**////<summary>
Write return new Interface.common.dropdowntree in code (this);
</summary>
Dropdowntree Dropdowntree
{
Get
}
}
public sealed class Dropdowntree
{
Idropdowntree _dropdowntree;
Public Dropdowntree (Idropdowntree dropdowntree)
{
_dropdowntree = Dropdowntree;
}
/**////<summary>
Prefix for the tree
</summary>
<param name= "Islast" > is the last one in the sibling node </param>
<param name= "Haschild" > Does this node have child nodes </param>
<param name= "parentstring" > Parent node prefix symbol </param>
<returns> prefix of this node </returns>
private string Getprefix (bool islast, bool Haschild, string parentstring)
{
string result = String.Empty;
if (!string.isnullorempty (parentstring))
{
parentstring = Parentstring.remove (parentstring.length-1). Replace ("├", "│"). Replace ("└", "");
result = parentstring;
}
if (islast)
{
result = "└";
}
Else
{
result = = "├";
}
if (haschild)
{
result = = "┬";
}
Else
{
result = "-";
}
return result;
}
Tie down pull down menu #region bind set Pull Menu
/**////<summary>
Drop-down menu for binding link level
</summary>
<param name= "Ddlgoodstype" > into a bound dropdownlist</param>
<param name= "RemoveID" > Excluded bound Nodes id</param>
<param name= "Autodispose" > whether automatic release </param>
public void Bindtodropdownlist (DropDownList ddlgoodstype, String removeid,string parentid, bool autodispose)
{
if (Ddlgoodstype!= null)
{
ListItem listitem = null;
String currentid = parentid;//root node/parent ID
String currentsign = string.empty;//current node symbol;
string parrentsign = String.Empty; parent node symbol;
BOOL Haschild = true;//whether there are children
queue<string> parentkeylist = new queue<string> ()//Node ID with child nodes
queue<string> parentsignlist = new queue<string> ();//prefix Symbol for node ID
int itemindexof = 0;//location of parent node
while (Haschild)
{
int lastonecount = 1;//used to calculate whether the last one in the same level
dictionary<string, string> childlist = _dropdowntree.getchildcategory (CurrentID);//Get child node list
if (childlist!= null && childlist.count > 0)
{
if (!string.isnullorempty (RemoveID) && Childlist.containskey (RemoveID))
{
Childlist.remove (RemoveID);
}
foreach (keyvaluepair<string, string> entry in childlist)
{
if (_dropdowntree.getchildcategory (entry.key)!= null)//EXISTS child
{
Currentsign = Getprefix (Lastonecount = = Childlist.count, true, parrentsign);
ListItem = new ListItem (currentsign + entry.value, entry.key);
Parentkeylist.enqueue (Entry.key);//Current Node ID
Parentsignlist.enqueue (currentsign);//Current node symbol
}
else//does not exist child
{
Currentsign = Getprefix (Lastonecount = = Childlist.count, false, parrentsign);
ListItem = new ListItem (currentsign + entry.value, entry.key);
}
if (ddlgoodstype.items.count!= 0)
{
Itemindexof = String.IsNullOrEmpty (CurrentID)? Itemindexof + 1:ddlgoodstype.items.indexof (Ddlgoodstype.items.findbyvalue (currentid)) + Lastonecount;
}
Ddlgoodstype.items.insert (Itemindexof, ListItem);//Add child nodes
lastonecount++;
}
if (Parentkeylist.count > 0)//When a child node exists
{
CurrentID = Parentkeylist.dequeue ();
Parrentsign = Parentsignlist.dequeue ();
}
Else
{
Haschild = false;
}
}
Else
{
Break
}
}
if (autodispose)
{
_dropdowntree.dispose ();
}
}
}
/**////<summary>
Drop-down menu for binding link level
</summary>
<param name= "Ddlgoodstype" > into a bound dropdownlist</param>
public void Bindtodropdownlist (DropDownList ddlgoodstype)
{
Bindtodropdownlist (Ddlgoodstype, String.empty,null, true);
}
/**////<summary>
Drop-down menu for binding link level
</summary>
<param name= "Ddlgoodstype" > into a bound dropdownlist</param>
<param name= "RemoveID" > Excluded id</param>
public void Bindtodropdownlist (DropDownList ddlgoodstype, String RemoveID)
{
Bindtodropdownlist (Ddlgoodstype, Removeid,null, true);
}
/**////<summary>
Drop-down menu for binding link level
</summary>
<param name= "Ddlgoodstype" > into a bound dropdownlist</param>
<param name= "RemoveID" > Excluded IDs, if not, pass null</param>
<param name= "ParentID" > Start parent id</param>
public void Bindtodropdownlist (DropDownList ddlgoodstype, string removeid,string parentid)
{
Bindtodropdownlist (Ddlgoodstype, Removeid,parentid, true);
}
#endregion
}
}
The calling method is simple: 1. Inherit from Idropdowntree interface 2. Implement 3 interface methods implement interface code example [Dispose method to implement itself], the most important thing is to achieve the method of getting the child
Idropdowntree member #region Idropdowntree member
Public dictionary<string, String> getchildcategory (String parentid)
{
string where = "parentid= '" + parentid + "'";
if (String.IsNullOrEmpty (ParentID))
{
where = "ParentID is null or parentid= '" + guid.empty + "'";
}
list<goodscategorybean> _goodscategorylist = selectlist (0, where, String.Empty, false);
if (_goodscategorylist!= null && _goodscategorylist.count > 0)
{
dictionary<string, string> categorylist = new dictionary<string, string> ();
for (int i = 0; i < _goodscategorylist.count; i++)
{
Categorylist.add (_goodscategorylist[i].id.tostring (), _goodscategorylist[i].gategoryname);
}
return categorylist;
}//51aspx.com
return null;
}
Public Interface.common.dropdowntree Dropdowntree
{
get {return new Interface.common.dropdowntree (this);}
}
#endregion
Page Call code: Class name. dropdowntree.bindtodropdownlist (Drop-down control ID);