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!