asp.net realization of dropdownlist,treeview,listbox infinite Pole Classification Tree _ Practical Skills

Source: Internet
Author: User

This article describes the infinite Polar classification tree of asp.net implementation dropdownlist,treeview,listbox. Share to everyone for your reference, specific as follows:

#region DropDownList infinite recursive display hierarchy///<summary>///create an infinite rating drop-down list box///</summary>///<param name= "Ddlst" > Dropdown Control </param>///<param name= "DT" > Source datatable</param>///<param name= "text" >text field </param >///<param name= "value" >value field </param>///<param name= "ParentID" > Depth field for example Parentid</param
> public static void Createleveldropdown (DropDownList ddlst, DataTable dt, string text, string value, String parentid)
  {ArrayList AllItems = new ArrayList (); datarow[] rows = dt.
  Select (parentid + "= 0"); foreach (DataRow row in rows) createleveldropdownassistant (DT, ref allitems, Row, string.
  Empty, text, value, ParentID);
  listitem[] items = new Listitem[allitems.count];
  Allitems.copyto (items); Ddlst.
Items.addrange (items); ///<summary>///Recursive binding sub-node///</summary>///<param name= "DT" > Source datatable</param>///-<param N Ame= "items" > Array </param>///<param name= "ParentRow" > Current node &LT;/PARAM&GT <param name= "Curheader" > Prefix </param>///<param name= "text" >text field </param>///<param Name= "Value" >value field </param>///<param name= "parentid" > depth fields such as parentid</param> private static void Createleveldropdownassistant (DataTable dt, ref ArrayList items, DataRow parentrow, String curheader, string text, St Ring value, String parentid) {ListItem newitem = new ListItem (Curheader + until.cutstring (parentrow[text). ToString (), true), Parentrow[value].
  ToString ()); Items.
  ADD (NewItem); datarow[] rows = dt.
  Select (parentid + "=" + Newitem.value); for (int i = 0; i < rows. Length-1; i++) createleveldropdownassistant (DT, ref items, Rows[i], Curheader.replace ("Out", "┃").
  Replace ("┗", "out") + "Out", text, value, ParentID); If rows. Length > 0) createleveldropdownassistant (DT, ref items, Rows[rows. Length-1], Curheader.replace ("Out", "┃").
Replace ("┗", "out") + "┗", text, value, ParentID); #endregion #region TreeView Infinite recursive display hierarchical relation meshRecord Tree///<summary>///Create an infinite hierarchical directory tree treeview///</summary>///<param name= "treeview" >treeview Space </param >///<param name= "DT" > Data source datatable</param>///<param name= "text" >text field </param>///< param name= "value" >value field </param>///<param name= "parentid" > depth fields such as parentid</param> public static void Createleveltreeview (TreeView treeview, DataTable DT, string text, string value, String parentid) {DataView DV = dt.
  DefaultView; Dv.
  RowFilter = parentid + "= 0";
    foreach (DataRowView drv in DV) {TreeNode node = new TreeNode (); Node. Text = Drv[text].
    ToString (); Node. Value = Drv[value].
    ToString (); Node.
    Expanded = false; Treeview.
    Nodes.Add (node);
  Creattreeviewchildnode (DV, node, text, value, ParentID); }///<summary>///recursive binding child node///</summary>///<param name= "DV" > Source dataview</param>///<param Name= "ParentNode" > Current node </param>///<param name= "text" >text Field </param>///<param name= "value" >value field </param>///<param name= "ParentID" > Depth field for example parentid</ param> private static void Creattreeviewchildnode (DataView dv, TreeNode parentnode, string text, String value, String p Arentid) {dv.
  RowFilter = parentid + "=" + Parentnode.value;
    foreach (DataRowView row in DV) {TreeNode Replynode = new TreeNode (); Replynode.text = Row[text].
    ToString (); Replynode.value = Row[value].
    ToString ();
    replynode.expanded = false;
    PARENTNODE.CHILDNODES.ADD (Replynode);
  Creattreeviewchildnode (DV, Replynode, text, value, ParentID); }///<summary>///create an infinite hierarchical directory tree treeview///</summary>///<param name= "treeview" >treeview Space </param >///<param name= "DT" > Data source datatable</param>///<param name= "text" >text field </param>///< param name= "value" >value field </param>///<param name= "url" >url field </param>///<param name= " ParentID > Depth fields such as Parentid</param> public static void Createleveltreeview (TreeView treeview, DataTable DT, string text, string value, string URL, string pare Ntid) {DataView dv = dt.
  DefaultView; Dv.
  RowFilter = parentid + "= 0";
    foreach (DataRowView drv in DV) {TreeNode node = new TreeNode (); Node. Text = Drv[text].
    ToString (); Node. Value = Drv[value].
    ToString (); Node. NavigateUrl = Drv[url].
    ToString (); Node.
    Expanded = false; Treeview.
    Nodes.Add (node);
  Creattreeviewchildnode (DV, node, text, value, URL, parentid); }///<summary>///recursive binding child node///</summary>///<param name= "DV" > Source dataview</param>///<param Name= "ParentNode" > Current node </param>///<param name= "text" >text field </param>///<param name= "value" >value field </param>///<param name= "url" >url field </param>///<param name= "ParentID" > Depth field For example parentid</param> private static void Creattreeviewchildnode (DataView dv, TreeNode parentnode, string text, String value, StRing URL, string parentid) {dv.
  RowFilter = parentid + "=" + Parentnode.value;
    foreach (DataRowView row in DV) {TreeNode Replynode = new TreeNode (); Replynode.text = Row[text].
    ToString (); Replynode.value = Row[value].
    ToString (); Replynode.navigateurl = Row[url].
    ToString ();
    replynode.expanded = false;
    PARENTNODE.CHILDNODES.ADD (Replynode);
  Creattreeviewchildnode (DV, Replynode, text, value, URL, parentid); #endregion #region Create an infinite hierarchical listbox///<summary>///Create an infinite hierarchical listbox///</summary>///<param name= "Ddlst" >listbox control </param>///<param name= "DT" > Source datatable</param>///<param the "text" name= field </param>///<param name= "value" >value field </param>///<param name= "ParentID" > Depth field for example ParentID </param> public static void Createlevellistbox (ListBox ddlst, DataTable dt, string text, String value, string parent
  ID) {ArrayList allitems = new ArrayList (); datarow[] rows = dt. Select (ParentiD + "= 0"); foreach (DataRow row in rows) createlevellistboxassistant (DT, ref allitems, Row, string.
  Empty, text, value, ParentID);
  listitem[] items = new Listitem[allitems.count];
  Allitems.copyto (items); Ddlst.
Items.addrange (items); ///<summary>///Recursive binding sub-node///</summary>///<param name= "DT" > Source datatable</param>///-<param N Ame= "items" > Array </param>///<param name= "ParentRow" > Current node </param>///<param name= "Curheader" > Prefix </param>///<param name= "text" >text field </param>///<param name= "value" >value field </ param>///<param name= "parentid" > depth fields such as parentid</param> private static void Createlevellistboxassistant (DataTable DT, ref ArrayList items, DataRow parentrow, String curheader, string text, String V Alue, String parentid) {ListItem newitem = new ListItem (Curheader + until.cutstring (parentrow[text). ToString (), true), Parentrow[value].
  ToString ()); Items.
  ADD (NewItem); Datarow[]rows = dt.
  Select (parentid + "=" + Newitem.value); for (int i = 0; i < rows. Length-1; i++) createlevellistboxassistant (DT, ref items, Rows[i], Curheader.replace ("Out", "┃").
  Replace ("┗", "out") + "Out", text, value, ParentID); If rows. Length > 0) createlevellistboxassistant (DT, ref items, Rows[rows. Length-1], Curheader.replace ("Out", "┃").
Replace ("┗", "out") + "┗", text, value, ParentID);

 } #endregion

More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."

I hope this article will help you to ASP.net program design.

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.