TreeView obtains the selected Value and Text. Only the Text below can be obtained.

Source: Internet
Author: User

How does js get the value of the selected value of treeview checkbox? As I can only get text now
Function returnValue (){

Var tree = document. getElementById ("treeView"). getElementsByTagName ("INPUT ");
For (var I = 0; I <tree. length; I ++ ){
If (tree [I]. type = "checkbox" & tree [I]. checked ){
// Parent.doc ument. getElementById ()
Registry.opener.doc ument. getElementById ('textbox _ szbm '). value = tree [I]. nextSibling. firstChild. nodeValue; www.2cto.com

Window. close ();
}
}
}
 
 
TreeView setting checkbox Event _ doPostBack ()
When ASP. NET 2.0 uses the TreeView control, it finds the TreeNode object with the CheckBox control (Treeview node). If you select CheckBox, the page cannot be sent back. In MSDN, The TreeNodeCheckChanged event has a note: "A TreeNodeCheckChanged event is triggered when the check box of the TreeView control is sent to the server twice to change the status. This allows you to provide an event processing method, that is, to execute a custom routine (such as updating the database or displaying content) each time this event occurs ). Although the TreeNodeCheckChanged event is triggered during sending back, changing the check box does not cause sending back ." The framework itself does not provide a CheckBoX sending mechanism.
Even if you click the CheckBox button, it will not cause a PostBack request. In this way, the checkbox will be automatically sent back.
However, when building a tree, there is no way to define an event on TreeNode. we add this event to the TreeView.
 
TreeView1.Attributes. Add ("onclick", "postBackByObject ()"); // register a client event
 
1 <script type = "text/javascript">
2 function postBackByObject ()
3 {
4 var o = window. event. srcElement;
5 // determine whether the stimulated object is checkbox. If yes, the _ doPostBack ("", "") is triggered ("","");
6 // because the checkbox generated by the foreground is "<input type = 'checkbox'./>"
7 // so the judgment is as follows:
8 if (o. tagName = "INPUT" & o. type = "checkbox ")
9 {
10 _ doPostBack ("", ""); // Note: __dopostback is composed of two underscores "_"
11}
12}
13 </script>
 
In. NET, when all server controls are submitted to the server, the _ doPostBack ("", "") function is called.
The first parameter is the ID of the control you want to submit to the server, and the second parameter is the event parameter.
The _ doPostBack () function is not generated every time it is compiled in the background. It can be used to pull a TreeView or DataGrid. If not, you can add it in the background.
The prototype of _ doPostBack () is as follows:

1 <script type = "text/javascript">
2 <! --
3 var theForm = document. forms ['form1 '];
 

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.