asp.net treeview CheckBox Related Issues _ practical tips
Source: Internet
Author: User
private void Display ()
{
DT = new Tsorganize (). Organizeds ();
DataView dv = new DataView (DT);
TreeNode nodes = new TreeNode ();
Nodes. Text = "Cross-strait coffee";
Nodes. Value = "0";
if (dt. Rows.Count >= 1)
{
Dv. RowFilter = "Fparentid= '";
if (DV. Count >= 1)
{
foreach (DataRowView drrow in DV)
{
TreeNode Nodel = new TreeNode ();
Nodel. Text = Drrow. row["Forgname"]. ToString ();
Nodel. Value = Drrow. row["Forgno"]. ToString ();
Nodes. Childnodes.add (Nodel);
NodeList (DV, Nodel, Drrow). row["Forgno"]. ToString ());
}
}
}
TREEVLIST.NODES.ADD (Nodes);
}
Spanning tree
private void NodeList (DataView dv, TreeNode node, string parentid)
{
Dv. RowFilter = "fparentid= '" + parentid.tostring () + "'";
if (DV. Count >= 1)
{
foreach (DataRowView drrow in DV)
{
TreeNode Nodel = new TreeNode ();
Nodel. Text = Drrow. row["Forgname"]. ToString ();
Nodel. Value = Drrow. row["Forgno"]. ToString ();
Node. Childnodes.add (Nodel);
NodeList (DV, Nodel, Drrow). row["Forgno"]. ToString ());
}
}
}
============================================================
1.
TreeNodeCollection TNC = Treevlist.checkednodes;
Gets all the selected nodes in the tree
private void Getchecknode (TreeNodeCollection TNC)
{
foreach (TreeNode node in TNC)
{
if (node. Checked)
{
if (node. Childnodes.count = 0)
{
DataRow dr = Tblselchains.newrow ();
dr["Forgno"] = node. Value;
dr["forgname"] = node. Text.tostring ();
TBLSELCHAINS.ROWS.ADD (DR);
}
}
}
}
2. According to the value in the database, to the corresponding nodes of the Checked=true
<summary>
Dtploystore: is a table (saves data read from the database)
<para></para>
</summary>
TreeNodeCollection TNC = Treevlist.nodes;
if (Dtploystore!= null)
{
if (DtPloyStore.Rows.Count > 0)
{
for (int i = 0; i < DtPloyStore.Rows.Count; i++)
{
Getselectedtreenode (TNC, dtploystore.rows[i]["Forgno"). ToString ());
}
}
}
<summary>
Traverse the store tree to get the selected node
<para></para>
</summary>
<param name= "TNC" ></param>
public void Getselectedtreenode (TreeNodeCollection tnc,string checkdata)
{
foreach (TreeNode node in TNC)
{
if (node. Checked)
{
Node. Checked = true;
Break
}
Getselectedtreenode (node. ChildNodes, Checkdata);
}
}
3.javascript Implementation Select parent node, child node automatically selected
Background to add attributes to the TreeView
THIS.TREEVLIST.ATTRIBUTES.ADD ("onclick", "ontreenodechecked ()");
The following are written in the foreground javascript
function ontreenodechecked () {
var ele = window.event.srcElement;
if (Ele.type = = ' checkbox ') {
var childrendivid = ele.id.replace (' CheckBox ', ' Nodes ');
var div = document.getElementById (childrendivid);
if (div = = null) return;
var checkboxs = div.getelementsbytagname (' INPUT ');
for (var i = 0; i < checkboxs.length; i++) {
if (Checkboxs[i].type = = ' checkbox ')
checkboxs[i].checked = ele.checked;
}
}
4. Displaying a checkbox on the TreeView is actually very simple, just set showcheckboxes= "all"
If we want to display the TREEVIW layer, we can set the Expanddepth= "n" (n is the number, which is the number of layers you want to show, 0 for all layers)
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.