Treeview selection operation (checkbox)

Source: Internet
Author: User

 

// -- It is best to use checkbox to select operations ..
// -- Treeview binding example
Using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Data. SqlClient;


Public partial class _ Default: System. Web. UI. Page
{
Private string connstring = ConfigurationManager. ConnectionStrings ["ConnStr"]. ToString ();

Private bool isHaveCheckBox = false;
Private bool isExpanded = false;
Private DataTable dtTree = null;
Protected void Page_Load (object sender, EventArgs e)
{
// Response. Write ("tttttttttt ");
If (! IsPostBack)
{
AreaTree. Nodes. Add (getRootAreaTreeNode (false, false ));
}

}

/// <Summary>
/// Obtain the data of the root node that contains all the sub-nodes
/// </Summary>
/// <Param name = "haveCheckBox"> whether a node generates a CheckBox </param>
/// <Param name = "expanded"> whether to expand a node </param>
/// <Returns> </returns>
Public TreeNode getRootAreaTreeNode (bool haveCheckBox, bool expanded)
{
// DrPeng. HS. BR. AreaTree brTree = new drPeng. HS. BR. AreaTree ();

String maid = "0001"; // brTree. getRootAreaTreeID ();
String rootName = "China"; // brTree. getRootAreaTreeName ();
// Ds = brTree. getAllAreaTree ();

IsHaveCheckBox = haveCheckBox;
IsExpanded = expanded;

# Region populate root node
TreeNode rootNode = new TreeNode ();
RootNode. Text = rootName;
RootNode. Value = rootID;
// RootNode. = rootName;
// RootNode. NodeData = "0001 ";

Rootnode. Expanded = true;
// Rootnode. checkbox = ishavecheckbox;
# Endregion

Dataset dstree = sqlhelper. executedataset (connstring, commandtype. Text, "select * From tb_area ");
Dttree = dstree. Tables [0];
This. populateareatree (rootid, rootnode );

Return rootnode;
}

Private void populateareatree (string parentid, treenode pnode)
{

Datarow [] drows = dttree. Select ("parentareacode = '" + parentid + "'");

If (drows. length> 0)
{
Treenode node = NULL;
Foreach (datarow Drow in drows)
{
Node = new treenode ();
Node. Text = drow ["AreaName"]. ToString ();
Node. Value = drow ["AreaCode"]. ToString ();
// Node. DataItem = Node. Text + "|" + Node. Value;
Node. Expanded = isExpanded;
PNode. ChildNodes. Add (Node );
PopulateAreaTree (Node. Value, Node); // Recursion
}
}
}
}

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.