I haven't logged on for a long time. Recently I am reading treeview information, it is still a bit difficult to understand how to handle the data volumes in SQL data tables and manually add them to treeview.

Source: Internet
Author: User

The following section describes how to use the temporary view function to implement the treeview, but not the data that has not been added to the SQL view.
Protected void Page_Load (object sender, EventArgs e)
{
This. TreeView1.Nodes. Clear (); // Clear all vertices of the treeview first
Maketree (); // generate a treeview
TreeView1.DataBind (); // set data size
}

Protected void maketree ()
{
TreeNode RootNode; // defines a pixel
For (int I = 0; I <10; I ++) // generates 10 root nodes first.
{
RootNode = new TreeNode (); // The actual instance represents a mirror;
RootNode. Text = "root vertex" + I. ToString (); // you can specify a vertex to display file information.
RootNode. Value = I. ToString (); // set the vertex Value
This. TreeView1.Nodes. Add (RootNode); // Add the vertex to the TreeView control.
MakeChildNode
}
}

Protected void MakeChildNode (TreeNode tn, int ParentID)
{
TreeNode CHildNode;
For (int I = 0; I <ParentID; I ++)
{
CHildNode = new TreeNode ("sub-vertex" + I. ToString (), I. ToString ());
Tn. ChildNodes. Add (CHildNode );
// MakeChildNode (CHildNode, I); // the error message returned when the error message returned, before using the metric, determine whether there is a downstream metric at the specific metric point, or control the number of metric data.
}
}

Which of the following is a problematic generation? Too many ........
Protected void TV _binder ()
{
SqlConnection conn = DB. createConection ();
SqlCommand cmd = new SqlCommand ("select * from Dep", conn );
SqlDataAdapter adp = new SqlDataAdapter (cmd );
DataSet ds = new DataSet ();
Adp. Fill (ds, "Dep ");
Cmd. CommandText = "select * from Class ";
Adp = new SqlDataAdapter (cmd );
Adp. Fill (ds, "Class ");

If (ds. Tables ["Dep"]. Rows. Count> 0)
{
For (int I = 0; I <ds. Tables ["Dep"]. Rows. Count; I ++)
{// Insert the primary SQL statement into the primary SQL statement
TreeNode tn = new TreeNode ();
Tn. Text = ds. Tables ["Dep"]. Rows [I] ["DepthName"]. ToString ();
Tn. NavigateUrl = "NavMenu. aspx? Act = list & Dep = "+ ds. Tables [" Dep "]. Rows [I] [" DepID "]. ToString ();
This. TV _leftmenu.Nodes.Add (tn );
TV _ChildTreeNode (Convert. toInt32 (ds. tables ["Dep"]. rows [I] ["DepID"]. toString (), tn, ds. tables ["Class"]);
}
}
This. TV _treeview.DataBind ();
}

Protected void TV _ChildTreeNode (int DepID, TreeNode tn, DataTable dt)
{
Dt. DefaultView. RowFilter = "DepID ";
DataView dv = dt. DefaultView;
Adp. Fill (ds );
If (dv. Count> 0)
{
For (DataRowView drv in dv)
{// Insert the primary SQL statement into the primary SQL statement
TreeNode Child_tn = new TreeNode ();
Child_tn.Text = drv ["ClassName"]. ToString ();
Child_tn.NavigateUrl = "NavMenu. aspx? Act = list & Dep = "+ drv [" DepID "]. ToString ();
Tn. ChildNodes. Add (Child_tn );
TV _ChildTreeNode (Convert. ToInt32 (drv ["DepID"]. ToString (), Child_tn, dt );
}
}
}

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.