Implementation of tree menu code for provincial and municipal areas using asp.net c

Source: Internet
Author: User
Tags mysql tutorial

Implementation of tree menu code for provincial and municipal areas using asp.net c

Asp tutorial. net c implement provincial/municipal tree menu code

/// <Summary>
/// Method for creating dataset
/// </Summary>
/// <Param name = "nodes"> root node of the treeview </param>
/// <Param name = "ds"> dataset data set </param>
/// <Param name = "pid"> parent node </param>
Private void createtreeview (treenodecollection nodes, dataset ds, int pid)
{
// Define filtering Conditions
String SQL = string. format ("parentid = {0}", pid );

// Filter the set of qualified rows from dataset
Datarow [] drr = ds. tables [0]. select (SQL );

// Traverse the collection of rows
Foreach (datarow dr in drr)
{
// Create a treeview Node
Treenode tnode = new treenode ();
// Add to the root node
Nodes. add (tnode );
// Set the displayed text
// Tnode. imageurl = "images/foldericon1.gif ";
Tnode. text = dr ["purname"]. tostring ();
Tnode. value = dr ["purid"]. tostring ();
// Set the display path
Tnode. navigateurl = dr ["pururl"]. tostring ();
// Recursive call Method
Createtreeview (tnode. childnodes, ds, convert. toint32 (dr ["purid"]);
// Delete added rows from dataset to improve access efficiency
Ds. tables [0]. rows. remove (dr );

}
}
 

/// Method 2
 

Private void treeviewbind ()
{
String SQL _tr = "select id, pid, name from tab ";
Sqlconnection mysql tutorial conn = new sqlconnection (sqlconn );
Sqldataadapter mydataadapter = new sqldataadapter (SQL _tr, mysqlconn );
Mysqlconn. open ();
Mydataadapter. fill (ds_tr, "tree_show ");
Dataview dv = ds_tr.tables [0]. defaultview;
Dv. rowfilter = "pid = 0 ";
Treeview1.showcheckboxes = treenodetypes. none; // the checkbox is not displayed.
Foreach (datarowview drv in dv)
{
Treenode node = new treenode ();
Node. text = drv ["name"]. tostring ();
Node. value = drv ["id"]. tostring ();
Node. expanded = false;
Treeview1.nodes. add (node );
Addnode (dv, node );
}
}

/// Recursively bind a subnode

Private void addnode (dataview dv, treenode node)
{
Dv. rowfilter = "pid = '" + node. value + "'";
Foreach (datarowview row in dv)
{
Treenode replynode = new treenode ();
Replynode. text = row ["name"]. tostring ();
Replynode. value = row ["id"]. tostring ();
Replynode. expanded = false;
Node. childnodes. add (replynode );
Addnode (dv, replynode );
}
}
 
// Method 3
 
/// Treeview recursively binds data
/// Bind province to query the city Based on pif
Private void inittree (treenodecollection nds, string parentid)
{
Dataview dv = new dataview ();
Treenode tmpnd;
String intid;
Dv. table = ds. tables ["tree"];
Dv. rowfilter = "parentid = '" + parentid + "'";
Foreach (datarowview drv in dv)
{
Tmpnd = new treenode ();
Tmpnd. tag = drv ["nodeid"]. tostring ();
Tmpnd. text = drv ["nodename"]. tostring ();
Nds. add (tmpnd );
Intid = drv ["parentid"]. tostring ();
Inittree (tmpnd. nodes, tmpnd. tag. tostring ());
}

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.