) Treeview usage highlights

Source: Internet
Author: User
Install and use the Asp.net Treeview (how to package and publish the Treeview) (initialize the Treeview with the checkbox selection box, and operate the Treeview client: select the parent node and automatically select all child nodes, automatically select the parent node after the child node is selected) (precise positioning of the Treeview node)
Http://www.cnblogs.com/adandelion/archive/2005/11/29/235681.html

Http://ghost527.cnblogs.com/archive/2005/12/30/308363.html

Http://www.aspxboy.com/private/showthread.asp? Postid = 840

1.
Http://msdn.microsoft.com/downloads/samples/internet/ASP_DOT_NET_ServerControls/WebControls/default.asp
The downloaded version is a version suffixed with BAT.
(1)buyun.direct the buyun.bat to the csc.exe path to generate Microsoft. Web. UI. webcontrols. dll.
(2) create an empty directory webctrl_client \ defaults 0 under wwwroot.
(3) copy the file under build \ runtime to webctrl_client \ Runtime 0.
(4) Select the custom toolbox of the Toolbox and add Microsoft. Web. UI. webcontrols. dll.
Some troubles
However, if you can find that the suffix is the automatic installation version of MSI, just click Next (I have been using this version, Hoho)
After installation, add the Treeview to the Toolbox through "Custom toolbox"-> ". NET Framework component ".

2. Unable to display during running
This is generally the version of Treeview. It is best to download the English version of Automatic Installation and reinstall it. Before installation, add or delete it first.ProgramDetach the original version

3. Display format error (non-Tree display)
Treeview requires that the client browser version be ie5.5 or later. It is recommended that the client be upgraded to ie6.0

4. Use Treeview IN THE FRAMEWORK
Sets the navigateurl and target attributes to update other frames.

5. The treenode class cannot be found.
To use Treeview, it is best to add namespace: using Microsoft. Web. UI. webcontrols;

6. traverse the Treeview node (RecursionAlgorithm)
Private void page_load (Object sender, system. eventargs E)
{
Getallnodetext (treeview1.nodes );
}
Void getallnodetext (treenodecollection TNC)
{
Foreach (treenode node in TNC)
{
If (node. nodes. Count! = 0)
Getallnodetext (node. nodes );
Response. Write (node. Text + "");
}
}

7. Obtain the parent node of the node.
Treenode pnode;
If (node. parent is treenode)
Pnode = (treenode) node. parent;
Else
// Node is Root Node

8. Modify the Treeview style (example)
<Iewc: Treeview id = "treeview1" runat = "server" hoverstyle = "color: Blue; Background: #00 ffcc;" defaultstyle = "Background: red; color: yellow; "selectedstyle =" color: red; Background: #00ff00; ">
UseCode:
Treeview1.defaultstyle ["font-size"] = "20pt ";

9. The node is not submitted when it is expanded. It is submitted only when the node selection is changed.
Set autopostback to false;
Add <body onload = "inittree ()">
Then write in pageload:
String strtreename = "treeview1 ";
String strref = page. getpostbackeventreference (treeview1 );
String strscript = "<script language = \" javascript \ "> \ n" + "<! -- \ N "+" function inittree () {\ n "+" "+ strtreename +". onselectedindexchange = function () {\ n "+" If (event. oldtreenodeindex! =
Event. newtreenodeindex) \ n "+" this. queueevent ('onselectedindexchang', event. oldtreenodeindex + ',' + event. newtreenodeindex); \ n "+" window. setTimeout ('"+ strref. replace ("'", "\'") + "', 0, 'javascript '); \ n "+"} \ n "+"} \ n "+" // --> \ n "+" </SCRIPT> ";
Page. registerclientscriptblock ("inittree", strscript );

In this way, you can only submit the changed node!

10. Combine Treeview with XML
Set the XML file to the following format, and directly set treenodesrc to the XML file.
<? XML version = "1.0" encoding = "gb2312"?>
<Treenodes>
<Treenode text = "node0" expanded = "true">
<Treenode text = "node1"/>
<Treenode text = "node2"/>
</Treenode>
<Treenode text = "node3" navigateurl = "3. aspx"/>
</Treenodes>
Or use the code
Treeview1.treenodesrc = "A. xml ";
Treeview1.databind ();

 

Client control Treeview
Http://expert.csdn.net/Expert/topic/1382/1382892.xml

1. Set the selected node. For example, select the second node.
Function setselnode ()
{
Treeview1.selectednodeindex = "1 ";
}

2. Get the text, ID, or nodedata of the selected node.
Function getattribute ()
{
Alert (treeview1.gettreenode (treeview1.selectednodeindex). getattribute ("text "));
}
Replace text with ID or nodedata to obtain the ID or nodedata of the selected node.

3. Modify node attributes, such as modifying the text of the first node
Function modifynode ()
{
VaR node = treeview1.gettreenode ("0 ");
Node. setattribute ("text", "hgknight ");
}

4. Click nodes.
Function treeview1.onclick ()
{
Alert (treeview1.gettreenode (treeview1.clickednodeindex). getattribute ("text "));
}

5. add nodes
Function addnode ()
{
VaR node = treeview1.createtreenode ();
Node. setattribute ("text", "hgknight ");
Treeview1.add (node );
}

6. js traverses all nodes
VaR allrootnode = new array ();
Allrootnode = treeview1.getchildren ();
Alertnode (allrootnode );

Function alertnode (nodearray)
{
If (parseint (nodearray. Length) = 0)
Return;
Else
{
For (I = 0; I <nodearray. length; I ++)
{
VaR cNode;
CNode = nodearray [I];
Alert (cNode. getattribute ("text "));
If (parseint (cNode. getchildren (). Length )! = 0)
Alertnode (cNode. getchildren ());
}
}
}

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.