Retrieve the checkbox value in the Treeview by traversing the tree.

Source: Internet
Author: User
Tags tagname

This example is used to create a tree with a checkbox in the Treeview and obtain the checkbox selection value. The project code is as follows:

 

 

JS part: treecheckbox. js

--------------------------------------------------------

Function selectcheckbox ()
{
VaR o = Window. event. srcelement;
VaR inputobj;
If (O. tagname = "input" & O. type = "checkbox ")
{
 
VaR parentobj = O. parentnode;
Inputobj = O;
While (parentobj. tagname! = "Table ")
{
Parentobj = parentobj. parentnode
 
}
VaR nextobj = parentobj. nextsibling
If (nextobj. tagname! = "Div ")
Return;
 
VaR x = nextobj. getelementsbytagname ("input ");
VaR S = "";
For (VAR I = 0; I <X. length; I ++)
{
If (X [I]. tagname = "input" & X [I]. type = "checkbox ")
{
If (inputobj. Checked)
X [I]. Checked = true
Else
X [I]. Checked = false

}
}
}
}

 

 

 

 

CSS Section

--------------------------------------------------------

<Asp: Treeview id = "linkstreeview" font-names = "Arial" forecolor = "white" enableclientscript = "true"
Populatenodesfromclient = "true" ontreenodepopulate = "populatenode" runat = "server"
Expanddepth = "1">
<Nodes>
<Asp: treenode text = "tree title" selectaction = "NONE" populateondemand = "true"/>
</Nodes>
</ASP: Treeview>

 

 

 

 

CS code:

------------------------------------------------------

 

 

/// <Summary>
/// Execute Treeview Based on the checkbox Selection
/// </Summary>
/// <Param name = "item"> Control name of the tree </param>
Public void getstring (treenodecollection item)
{

Foreach (treenode VaR in item)
{
If (var. Checked)
{
String procname = "p_infouser_createtinfouser ";
Sqlparameter [] prams = {
New sqlparameter ("@ userid", sqldbtype. nvarchar, 7 ),
New sqlparameter ("@ infoid", sqldbtype. INT)
};
Prams [0]. value = var. value;
Prams [1]. value = convert. toint32 (labinfiid. Text );
Try
{

If (dbhelper. runexecute (procname, prams)> 0)
{
Jshelper. Alert ("your authorization has been successful! ", This. Page );
Lbtninfosubid. Text = "";
Labinfosubid. Text = "user authorization successful ";

// Button for controlling the operation tree
Btnalerttree. Enabled = true;
Btnoutput. Enabled = false;

// Display and hide the control panel
Panelnotice. Visible = true;
Panelauthorize. Visible = false;
}
Else
{
Jshelper. Alert ("sorry, your operation is incorrect. Please check it! ", This. Page );
}
}
Catch (exception)
{
Throw;
}

}

// If (var. childnodes. Count> 0)
//{
// Getstring (var. childnodes );
//}
}

}

 

 

--------------------------------------------------------

The tree binding, as well as the checkbox usage for traversal, mainly depends on your own flexibility!

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.