//html
<asp:TreeView ID="TreeView1" ShowCheckBoxes="All" runat="server" NodeIndent="15"
>
<HoverNodeStyle Font-Underline="True"
ForeColor="#6666AA"
/>
<NodeStyle Font-Names="Arial"
Font-Size="9pt"
ForeColor="Black"
HorizontalPadding="1px"
NodeSpacing="0px"
VerticalPadding="1px"
></NodeStyle>
<ParentNodeStyle
Font-Bold="False"
/>
</asp:TreeView>
<script>
Sys.Application.add_load(jScript);
function jScript() {
$("[id*=TreeView1]
input[type=checkbox]").bind("click",
function () {
var table = $(this).closest("table");
if (table.next().length > 0 && table.next()[0].tagName
== "DIV") {
//Is Parent CheckBox
var childDiv = table.next();
var isChecked = $(this).is(":checked");
$("input[type=checkbox]", childDiv).each(function () {
if (isChecked) {
$(this).attr("checked",
"checked");
} else {
$(this).removeAttr("checked");
}
});
} else {
//Is Child CheckBox
var parentDIV = $(this).closest("DIV");
if ($("input[type=checkbox]",
parentDIV).length == $("input[type=checkbox]:checked",
parentDIV).length) {
$("input[type=checkbox]",
parentDIV.prev()).attr("checked", "checked");
} else {
$("input[type=checkbox]",
parentDIV.prev()).removeAttr("checked");
}
}
});
}
</script>
//result
No comments:
Post a Comment