Hi I've these check boxes in asp.net repeater
when I click the parent check box as you can see in this picture all child check boxes get check, in the other hand when I check the child check box the parent did not get selected. I'm using Jquery
to achieve this My current ASP.NET
code is as given below
<ul id='<%# "p_"+Eval("ApplicationId") %>' class="child-ul-hide child-ul">
<asp:Repeater ID="rptrPages" runat="server" OnItemDataBound="rptrPages_ItemDataBound">
<ItemTemplate>
<li>
<%-- <span id='<%# "sp_"+Eval("PageId") %>' class="parent arrow-right" state="hide"></span>--%>
<asp:Label ID="lblSpaces" runat="server" Text='<%# Eval("Spaces") %>'></asp:Label>
<asp:Literal ID="ltrArrowSpan" runat="server"></asp:Literal>
<label>
<asp:CheckBox ID="chkPage" runat="server" Text='<%# Eval("PageTitle") %>'
CssClass='<%# "page Pid_"+ Eval("ParentId")%>' PageId='<%# Eval("PageId") %>' ParentId='<%# Eval("ParentId") %>'
Checked='<%# Eval("IsEnable")== null ? false: Convert.ToBoolean(Eval("IsEnable").ToString()) %>' />
</label>
<asp:HiddenField ID="hdPageId" runat="server" Value='<%# Eval("PageId") %>' />
and my JavaScript
code is as following as you can see I'd tried a couple of other stuff and used Intermediate snippiest too but when they are invited to ASP.NET
Nothing goes as planed. many of you might suggest to use <input type='checkbox'/>
sorry I can't do that
$(document).ready(function () {
/* Hide Show Tree lis
*******************************************/
$(".parent").click(function () {
var ID = $(this).attr("id");
var state = $("#" + ID).attr("state");
if (state == "hide") {
$("#" + ID).attr('state', 'show');
$("#" + ID).addClass("arrow-down").removeClass("arrow-right");
ID = ID.replace("s", "");
$("#" + ID).addClass("child-ul-show").removeClass("child-ul-hide");
}
else {
$("#" + ID).attr('state', 'hide');
$("#" + ID).addClass("arrow-right").removeClass("arrow-down");
ID = ID.replace("s", "");
$("#" + ID).addClass("child-ul-hide").removeClass("child-ul-show");
}
});
// /* START Parent Enable CheckBox Click Event
// *********************************************/
$(".page input[type='checkbox']").click(function() {
var PageId = $(this).parent('.page').attr("PageId");
var parentId = $(this).parent('.page').attr("ParentId");
var EnableStatus = $(this).prop("checked");
// Check/ Uncheck Controls Checkboxes
$("." + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
//Check unCheck Childs Checkboxes
$(".Pid_" + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
$(".Pid_" + PageId + " input[type='checkbox']").each(function() {
PageId = $(this).parent('.page').attr("PageId");
EnableStatus = $(this).prop("checked");
$(".Pid_" + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
});
//$(".page input[type='checkbox']").prop('checked', false);
//$(".Pid_" + ParentId + " input[type='checkbox']").each(function() {
// debugger;
// EnableStatus = $(this).prop("checked");
// if (EnableStatus) {
// $(".page input[type='checkbox']").prop('checked', EnableStatus);
// return false;
// }
//});
debugger;
parentId = parseInt(parentId);
if (parentId>0) {
$("input[type='checkbox'][ParentId^='" + parentId + "']").prop('checked', true);
}
/*/ */
//$('input[name=' + parentId + '][value=Done][type=checkbox]:not(:checked)').attr({
// checked: 'checked',
// disabled: 'disabled'
//});
});
What I can see is that you've a single check box that at a time is acting as a parent as well as a child, I don't have any idea what made you to do that. Lets get to the answer.
Add an attribute to the class as ParentId='<%# Eval("ParentId")
get that attribute
var ParentId = $(this).parent('.page').attr("ParentId");
use the JavaScript parseInt
to parse your id as integer than do this one
ParentId= parseInt(ParentId);
if (ParentId > 0) {
$(".p_" + ParentId + " input[type='checkbox']").prop('checked', false);
$(".Pid_" + ParentId + " input[type='checkbox']").each(function () {
EnableStatus = $(this).prop("checked");
if (EnableStatus)
{
$(".p_" + ParentId + " input[type='checkbox']").prop('checked', EnableStatus);
}
});
}
Hope this will help you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.