Asp.Net树视图控件折叠后未选中子复选框.如何处理这个问题
Asp.Net Treeview control collapsed does not select the child checkbox. How to handle this?
我有一个ASP。具有复选框的。NET树视图控件。
使用这个jQuery检查所有的子复选框,当父被选中。这段代码运行良好。
<script type="text/javascript">
function CheckboxGroupSelection() {
$('.tree :checkbox').on('change', function () {
var checked = this.checked;
var $elem = $(this).closest('table');
var depth = $elem.find('div').length;
var $childs = $elem.nextAll('table');
$childs.each(function () {
var $child = $(this);
var d = $child.find('div').length;
if (d == depth) {
return false;
}
$child.find(':checkbox').prop('checked', checked);
});
});
}
</script>
现在,问题在这里:当父节点被折叠,然后选中父节点复选框,逻辑上所有的子复选框都应该被选中。但是这个jQuery不能用于此目的,因为jQuery使用HTML标记来查找和检查复选框,并且,当父节点折叠时,我无法看到子节点标记。
如何处理?或者是否有任何方法可以使用c#或vb.net背后的代码来实现这一点?
折叠时的HTML标记:
<div style="font-size: 11px; font-family: Tahoma; font-weight: bold; text-align: left;" class="tree" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><a href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$Treecontrol_Left_0$Tree_Index','t1730b784-94ca-42d3-80aa-1c9c064e271c')"><img style="border-width:0;" alt="Collapse Clinics" src="../Uploadedimages/System/Static_Images/TreeLineImages/dashminus.gif"></a></td><td style="width:295px;"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn0CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn0CheckBox"><span style="text-decoration:none;" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext0">Clinics</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><a href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$Treecontrol_Left_0$Tree_Index','t1730b784-94ca-42d3-80aa-1c9c064e271c''726a5894-6495-4bd2-90fa-1c0eb60f9406')"><img style="border-width:0;" alt="Expand GP Clinics" src="../Uploadedimages/System/Static_Images/TreeLineImages/tplus.gif"></a></td><td style="width:295px;"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn1CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn1CheckBox"><span style="text-decoration:none;" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext1">GP Clinics</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><img alt="" src="../Uploadedimages/System/Static_Images/TreeLineImages/t.gif"></td><td style="width:295px;"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn7CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn7CheckBox"><span style="text-decoration:none;" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext7">Other Clinics</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><img alt="" src="../Uploadedimages/System/Static_Images/TreeLineImages/l.gif"></td><td style="width:295px;"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn8CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn8CheckBox"><span style="text-decoration:none;" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext8">Polyclinics</span></td>
</tr>
</tbody></table>
</div>
Public Sub tree_TreeNodeCheckChanged(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
If e IsNot Nothing AndAlso e.Node IsNot Nothing Then
If e.Node.ChildNodes.Count > 0 Then
CheckTreeNodeRecursive(e.Node, e.Node.Checked)
End If
End If
End Sub
Private Sub CheckTreeNodeRecursive(ByVal parent As TreeNode, ByVal fCheck As Boolean)
For Each child As TreeNode In parent.ChildNodes
If child.Checked <> fCheck Then
child.Checked = fCheck
End If
If child.ChildNodes.Count > 0 Then
CheckTreeNodeRecursive(child, fCheck)
End If
Next
End Sub
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- keyup事件处理程序更改焦点不适用于快速键入
- 如何使用jquery处理php循环通过元素
- angular.js没有'无法在PhoneGap中处理视图标记
- Webpack/Rect:遵循egghead.io教程,但出现错误:您可能需要一个合适的加载程序来处理此文件类型
- 提示使用服务器端事件处理程序激活JavaScript
- javascript:如何在antlr生成的Lexer中进行错误处理
- 如何编写一个具有公共标头的批处理
- 在同一个服务工作者中处理service-worker.js有任何影响吗
- 如何处理node.js节点mongodb中的连接和查询队列
- 通过命令行/批处理文件打开页面时,将javascript代码注入Google Chrome
- 如何处理10页以上的静态页眉/页脚
- 将事件处理程序绑定到任何可能的事件
- 通过ajax将坐标传递到php服务器端,并在处理后检索到javascript
- python到“;流“;字典处理
- 使用javascript进行实时图像处理
- 导入jQuery脚本获胜'我不处理html文件
- Javascript无法处理表单提交
- JavaScript 任务调度程序(批处理处理)
- RegEx在VBA和JavaScript中的处理方式有何不同?