) Solution: use JavaScript in Treeview to select all checkboxes

Source: Internet
Author: User
To sum up this work, I understand several key points:
1. javascript can directly reference the. NET Server-side control, but the problem is that the Control ID will automatically add a namespace after compilation, so pay special attention here.
2. Using JavaScript makes it convenient and effective to perform operations on the Treeview without the need for PostBack.
3. The display of the Space status is different from that of the actual storage, so pay attention to it.
Add the following to the C # file: Treeview. Attributes. Add ( " Oncheck " , " Tree_oncheck () " );

Major Javascript Code As follows: < Script Language = " Javascript " >
<! --

Function Tree_oncheck ()
{
VaR Node = Treeview. gettreenode (event. treenodeindex );
VaR Pchecked = Node. getattribute ( " Checked " );
Setcheck (node, pchecked );
Treeview. queueevent ('oncheck', node. getnodeindex ());
}

Function Setcheck (node, PC)
{
VaR Childnode =   New Array ();
Childnode = Node. getchildren ();
If (Parseint (childnode. length) ! =   0 )
{
For ( VaR I =   0 ; I < Childnode. length; I ++ )
{
VaR CNode = Childnode [I];
If (CNode. getattribute ( " Checked " ) ! = PC)
{
If (Parseint (cNode. getchildren (). length) ! =   0 )
Setcheck (cNode, PC );
CNode. setattribute ( " Checked " , PC );
Treeview. queueevent ('oncheck', cNode. getnodeindex ());
}
}
}
}

// -->
</ Script >

To implement the entire function, you need to modify a bug of the Microsoft Treeview control.
You need to modify Inetpub \ wwwroot \ webctrl_client \ defaults 0 \ Treeview. HTC.
Put the first line in function docheckboxclick (EL,
El. Checked =! El. checked;
Changed:
El. Checked =! El. getattribute ("checked ");

Blogger Note: This articleArticleThe method mentioned above will go wrong after trial. For more comprehensive solutions, see Treeview parent-child linkage effect to keep the node status consistent.

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.