A method of asp.net datagridtree down-pull tree

Source: Internet
Author: User
Tags bind

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


{


/**////&lt;summary&gt;


Return dictionary ID, text, if no child node returns null


&lt;/summary&gt;


&lt;param name= "ParentID" &gt; Parent node id&lt;/param&gt;


&lt;returns&gt;&lt;/returns&gt;


Dictionary&lt;string, string&gt; getchildcategory (string parentid);


/**////&lt;summary&gt;


Write return new Interface.common.dropdowntree in code (this);


&lt;/summary&gt;


Dropdowntree Dropdowntree


{


Get


}


}


public sealed class Dropdowntree


{


Idropdowntree _dropdowntree;


Public Dropdowntree (Idropdowntree dropdowntree)


{


_dropdowntree = Dropdowntree;


}


/**////&lt;summary&gt;


Prefix for the tree


&lt;/summary&gt;


&lt;param name= "Islast" &gt; is the last one in the sibling node &lt;/param&gt;


&lt;param name= "Haschild" &gt; Does this node have child nodes &lt;/param&gt;


&lt;param name= "parentstring" &gt; Parent node prefix symbol &lt;/param&gt;


&lt;returns&gt; prefix of this node &lt;/returns&gt;


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


/**////&lt;summary&gt;


Drop-down menu for binding link level


&lt;/summary&gt;


&lt;param name= "Ddlgoodstype" &gt; into a bound dropdownlist&lt;/param&gt;


&lt;param name= "RemoveID" &gt; Excluded bound Nodes id&lt;/param&gt;


&lt;param name= "Autodispose" &gt; whether automatic release &lt;/param&gt;


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&lt;string&gt; parentkeylist = new queue&lt;string&gt; ()//Node ID with child nodes


queue&lt;string&gt; parentsignlist = new queue&lt;string&gt; ();//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&lt;string, string&gt; childlist = _dropdowntree.getchildcategory (CurrentID);//Get child node list


if (childlist!= null &amp;&amp; childlist.count &gt; 0)


{


if (!string.isnullorempty (RemoveID) &amp;&amp; Childlist.containskey (RemoveID))


{


Childlist.remove (RemoveID);


}


foreach (keyvaluepair&lt;string, string&gt; 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 &gt; 0)//When a child node exists


{


CurrentID = Parentkeylist.dequeue ();


Parrentsign = Parentsignlist.dequeue ();


}


Else


{


Haschild = false;


}


}


Else


{


Break


}

}


if (autodispose)


{


_dropdowntree.dispose ();


}


}


}


/**////&lt;summary&gt;


Drop-down menu for binding link level


&lt;/summary&gt;


&lt;param name= "Ddlgoodstype" &gt; into a bound dropdownlist&lt;/param&gt;


public void Bindtodropdownlist (DropDownList ddlgoodstype)


{


Bindtodropdownlist (Ddlgoodstype, String.empty,null, true);


}


/**////&lt;summary&gt;


Drop-down menu for binding link level


&lt;/summary&gt;


&lt;param name= "Ddlgoodstype" &gt; into a bound dropdownlist&lt;/param&gt;


&lt;param name= "RemoveID" &gt; Excluded id&lt;/param&gt;


public void Bindtodropdownlist (DropDownList ddlgoodstype, String RemoveID)


{


Bindtodropdownlist (Ddlgoodstype, Removeid,null, true);


}


/**////&lt;summary&gt;


Drop-down menu for binding link level


&lt;/summary&gt;


&lt;param name= "Ddlgoodstype" &gt; into a bound dropdownlist&lt;/param&gt;


&lt;param name= "RemoveID" &gt; Excluded IDs, if not, pass null&lt;/param&gt;


&lt;param name= "ParentID" &gt; Start parent id&lt;/param&gt;


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&lt;string, String&gt; getchildcategory (String parentid)


{


string where = "parentid= '" + parentid + "'";


if (String.IsNullOrEmpty (ParentID))


{


where = "ParentID is null or parentid= '" + guid.empty + "'";


}


list&lt;goodscategorybean&gt; _goodscategorylist = selectlist (0, where, String.Empty, false);


if (_goodscategorylist!= null &amp;&amp; _goodscategorylist.count &gt; 0)


{


dictionary&lt;string, string&gt; categorylist = new dictionary&lt;string, string&gt; ();


for (int i = 0; i &lt; _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);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.