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 ());
}