How to make my nested listview collapsable and expandable - javascript

I have a nested ListView like this :
<asp:ListView runat="server" ID="lvOuter" DataKeyNames="camp_code" OnItemDataBound="lvOuter_ItemDataBound">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<%# Eval("camp_name") %>
<asp:HiddenField ID="hf_camp_code" runat="server" Value='<%# Eval("camp_code") %>' />
<asp:ListView runat="server" ID="lvInner">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<asp:HiddenField ID="hf_main_code" runat="server" Value='<%# Eval("main_code") %>' />
<asp:HiddenField ID="hf_year" runat="server" Value='<%# Eval("year") %>' />
<asp:LinkButton ID="lbtn_dep" runat="server" CommandName="get_dep"><%# Eval("name") %> (<%# Eval("dep_count") %>)</asp:LinkButton>
</li>
</ItemTemplate>
<EmptyDataTemplate>
<ul>
<li>---</li>
</ul>
</EmptyDataTemplate>
</asp:ListView>
</li>
</ItemTemplate>
<EmptyDataTemplate>
---
</EmptyDataTemplate>
</asp:ListView>
What i want to do is :
Collapsing to the outer list view in the beginning and expand under demand .
for example :
- 1-OUTER1
1.1 INNER1
1.2 INNER2
1.3 INNER3
- 2-OUTER2
2.1 INNER1
2.2 INNER2
2.3 INNER3
I want the following in the beginning :
+OUTER1
+OUTER2
How to get this behavior using my nested ListView ?
From FireBug :
<div>
<ul>
<li>
Computer
<input id="ctl00_ContentPlaceHolder1_lvOuter_ctrl0_hf_camp_code" type="hidden" value="1" name="ctl00$ContentPlaceHolder1$lvOuter$ctrl0$hf_camp_code">
<ul>
<li>
<input id="ctl00_ContentPlaceHolder1_lvOuter_ctrl0_lvInner_ctrl0_hf_main_code" type="hidden" value="1" name="ctl00$ContentPlaceHolder1$lvOuter$ctrl0$lvInner$ctrl0$hf_main_code">
<input id="ctl00_ContentPlaceHolder1_lvOuter_ctrl0_lvInner_ctrl0_hf_year" type="hidden" value="2012" name="ctl00$ContentPlaceHolder1$lvOuter$ctrl0$lvInner$ctrl0$hf_year">
<a id="ctl00_ContentPlaceHolder1_lvOuter_ctrl0_lvInner_ctrl0_lbtn_dep" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$lvOuter$ctrl0$lvInner$ctrl0$lbtn_dep','')">jm</a>
</li>
....

http://jsfiddle.net/EsWv3/1/
$("li.parent").click( function() {
$(this).next(".child").toggle("fast");
});
I think this could work for you

Related

How to validate dynamically created Checkboxlist And RadioButtonlist

I am trying to create a dynamic Multiple-choice Question Quiz, where we have different categories in which there are multiple questions with their individual options. I need to validate that at least one option is selected.
Below is the aspx code which I am using to bind the data:
<asp:ListView ID="lv_cat" runat="server" OnItemDataBound="lv_cat_ItemDataBound">
<EmptyDataTemplate></EmptyDataTemplate>
<ItemTemplate>
<div class="step">
<h4 style="text-align: center;"><%# Eval("Cat_name") %></h4>
<asp:Label ID="lbl_Cat_id" runat="server" Text='<%# Eval("cat_id") %>' hidden="true"></asp:Label>
<asp:ListView ID="Lv_question" runat="server" OnItemDataBound="Lv_question_ItemDataBound">
<EmptyDataTemplate></EmptyDataTemplate>
<ItemTemplate>
<div class="row">
<div class="col-md-10">
<h3><%# Eval("Question") %></h3>
<asp:Label ID="lbl_Q_Id" runat="server" Text='<%# Eval("Q_id") %>' hidden="true"></asp:Label>
<asp:Label ID="lbl_Q_ID_Status" runat="server" Text='<%# Eval("status") %>' hidden="true"></asp:Label>
<%-- <ul class="data-list-2">
<asp:ListView ID="Lv_Answer_check" runat="server" >
<EmptyDataTemplate></EmptyDataTemplate>
<ItemTemplate>
<li>
<input name="rate" type="checkbox" class="required check_radio" id="checkbox" value='<%# Eval("A_id") %>'><label><%# Eval("answers") %></label></li>
</ItemTemplate>
</asp:ListView>
<asp:ListView ID="Lv_Answer_Radio" runat="server" >
<EmptyDataTemplate></EmptyDataTemplate>
<ItemTemplate>
<li>
<input name="rate" type="radio" id="radiobutton" class="required check_radio" value='<%# Eval("A_id") %>'><label> <%# Eval("answers") %></label></li>
</ItemTemplate>
</asp:ListView>
</ul>
</br>--%>
<asp:RadioButtonList ID="Rbl_options" runat="server" Style="text-align: left; margin-left: 30px;" >
</asp:RadioButtonList>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" name="CheckBoxList1" Style="text-align: left; margin-left: 30px;" ></asp:CheckBoxList>
</div>
</div>
</ItemTemplate>
</asp:ListView>
</div>
</ItemTemplate>
</asp:ListView>
and below is the javascript code which I am tried to implement.
<script>
$("input[type='checkbox']").addClass("answer_check");
$(".answer_check").each(function () {
$(this).rules("add", {
required: true,
messages: {
required: "please select atleast one of the below"
}
});
}); </script>

My javascript is not working with my page in asp.net

Recently I am working on asp.net application but my found that my script is not working and don't know why even I tested in the fiddle.
I want my list box to be filtered when user key in any keyword in the textbox.
My list box ID is "ItemList".
My textbox ID is "txtSearchItem".
here is my script for the page:
<%# Page Title="" Language="C#" MasterPageFile="~/Staff/Staff.Master" AutoEventWireup="true" CodeBehind="AddPackage.aspx.cs" Inherits="ExpressPrintingSystem.Staff.Owner.Package.AddPackage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
$(document.getElementById("<%=txtSearchItem.ClientID%>")).on("keyup", function () {
var search = this.value;
$("option", document.getElementById("<%= ItemList.ClientID %>")).show().filter(function () {
return $(this).text().toLowerCase().indexOf(search.toLowerCase()) < 0;
}).hide();
});
</script>
</asp:Content>
Here is the ListBox with is located in a table:
<td><asp:TextBox ID="txtSearchItem" TextMode="Search" Width="200px" runat="server" ClientIDMode="Static"/><br />
<asp:ListBox ID="ItemList" runat="server" Width="200px" DataSourceID="sdsItem" ClientIDMode="static" DataTextField="ItemName" DataValueField="ItemID"></asp:ListBox>
<asp:SqlDataSource ID="sdsItem" runat="server" ConnectionString="<%$ ConnectionStrings:printDBServer %>" SelectCommand="SELECT [ItemID], [ItemName] FROM [Item] WHERE ([ItemID] LIKE '%' + #keyword + '%') OR ([ItemName] LIKE '%' + #keyword + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="txtSearchItem" DefaultValue="I" Name="keyword" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
</td>
I not sure where is the error occur. I want the option tag to be hidden when the keywords in the text box is not match with the keywords user type in. The ListBox is linked with a datasource which will call all the record of the item out. Please help me.
Here is my whole complete code:
<%# Page Title="" Language="C#" MasterPageFile="~/Staff/Staff.Master" AutoEventWireup="true" CodeBehind="AddPackage.aspx.cs" Inherits="ExpressPrintingSystem.Staff.Owner.Package.AddPackage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
$(document.getElementById("<%=txtSearchItem.ClientID%>")).on("keyup", function () {
var search = this.value;
$("option", document.getElementById("<%= ItemList.ClientID %>")).show().filter(function () {
return $(this).text().toLowerCase().indexOf(search.toLowerCase()) < 0;
}).hide();
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphStaffContent" runat="server">
<h1>Add Package</h1>
<asp:Label ID="lblError" runat="server" ForeColor="Red" Text=""></asp:Label>
<table>
<tr>
<td><asp:Label ID="lblName" runat="server" Text="Name:"></asp:Label></td>
<td><asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtName" ForeColor="Red" ErrorMessage="Please fill up the the Name field."></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td><asp:Label ID="lblSupport" runat="server" Text="Support Files:"></asp:Label></td>
<td><asp:CheckBoxList ID="cblSupport" runat="server"></asp:CheckBoxList></td>
</tr>
<tr>
<td><asp:Label ID="lblType" runat="server" Text="Type of Package:"></asp:Label></td>
<td><asp:DropDownList ID="ddlType" runat="server" Height="17px" Width="128px"></asp:DropDownList></td>
</tr>
<tr>
<td><asp:Label ID="lblItems" runat="server" Text="Package's Items:"></asp:Label></td>
<td><asp:Table ID="tblPackageItems" runat="server" Width="100%">
<asp:TableRow>
<asp:TableCell>Item</asp:TableCell>
<asp:TableCell>Quantity</asp:TableCell>
</asp:TableRow>
</asp:Table> </td>
<td><asp:TextBox ID="txtSearchItem" TextMode="Search" Width="200px" runat="server" ClientIDMode="Static"/><br />
<asp:ListBox ID="ItemList" runat="server" Width="200px" DataSourceID="sdsItem" ClientIDMode="static" DataTextField="ItemName" DataValueField="ItemID"></asp:ListBox>
<asp:SqlDataSource ID="sdsItem" runat="server" ConnectionString="<%$ ConnectionStrings:printDBServer %>" SelectCommand="SELECT [ItemID], [ItemName] FROM [Item] WHERE ([ItemID] LIKE '%' + #keyword + '%') OR ([ItemName] LIKE '%' + #keyword + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="txtSearchItem" DefaultValue="I" Name="keyword" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td><asp:Label ID="lblEstPrice" runat="server" Text="Estimated Price (RM):"></asp:Label></td>
<td><asp:Label ID="lblEstimatedPrice" runat="server" Text="0"/></td>
</tr>
<tr>
<td><asp:Label ID="lblPrice" runat="server" Text="Package Price (RM):"></asp:Label></td>
<td><asp:TextBox ID="txtPrice" runat="server"></asp:TextBox></td>
</tr>
</table>
<asp:Button ID="btnSubmit" runat="server" Text="Add Package"/>
<asp:Button ID="btnCancel" runat="server" Text="Cancel"/>
</asp:Content>
This is my master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Staff.master.cs" Inherits="ExpressPrintingSystem.Staff.Staff" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Staff Portal</title>
<link rel="stylesheet" href="~/styles/main.css" type="text/css" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<div id="page">
<form runat="server">
<div id="header">
<asp:SiteMapDataSource ID="SiteMapDataSourceForStaff" SiteMapProvider="StaffSiteMap" runat="server" ShowStartingNode="false" />
<div>
<img src="<%=Page.ResolveUrl("~/Images/logo/long_logo.png")%>" alt=""/>
<ul id="navigation">
<li class="selected">
Home
</li>
<asp:Repeater runat="server" ID="menu" DataSourceID="SiteMapDataSourceForStaff">
<ItemTemplate>
<li>
<asp:HyperLink runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
<asp:Repeater runat="server" DataSource='<%# ((SiteMapNode) Container.DataItem).ChildNodes %>'>
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:HyperLink runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
</asp:Repeater>
<li style="float:right;">
<asp:HyperLink ID="userInfoControl" runat="server"/>
<ul id="userMenu" runat="server">
</ul>
</li> </ul>
</div>
</div>
<div id="content">
<div>
<asp:ContentPlaceHolder ID="cphStaffContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
</form>
<footer id="footer">
<div class="footcontent">
<div>
<img src="<%=Page.ResolveUrl("~/Images/logo/long_logo.png")%>" alt=""/>
<ul>
<li>Services</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
<div class="footnote">
<div>
<p>© 2017 BY Express Printing System | ALL RIGHTS RESERVED</p>
</div>
</div>
</footer>
</div>
</body>
</html>
This kind of problem is usually encountered when there are conflicts between jQuery and other libraries. To stay out of trouble, call $.noConflict() and don't forget to run your jQuery code after the document is ready
$.noConflict();
jQuery(document).ready(function($){ /**/});
First create a JavaScript file instead of a script tag and than link that file in the master page like this:
<script src="<%=ResolveClientUrl("~/content/assets/vendor/jquery/dist/jquery.min.js")%>">
</script>

Handle click event of dropdown in c# by jquery

I have written code in aspx file
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<section>
<div>
<label>State</label>
<label class="select">
<asp:DropDownList ID="ddlState" runat="server" DataTextField="StateName" DataValueField="StateName">
</asp:DropDownList><i></i>
</label>
</div>
</section>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlCountry" />
</Triggers>
</asp:UpdatePanel>
<div>
<label>Country</label>
<label class="select">
<asp:DropDownList ID="ddlCountry" runat="server" ToolTip="Select country" DataTextField="CountryName"
DataValueField="CountryID" AutoPostBack="true" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
</asp:DropDownList><i></i>
<asp:Label ID="lblSelectCountryFirst" Visible="false" Text="Please Select Country" runat="server" ForeColor="Red">
</asp:Label>
</label>
</div>
</section>
Now I want that when user will click on state dropdown the label lblSelectCountryFirst should be visible. How to accomplish this in jquery.
Use OnClientClick and change visible=false to css style display:none;. Please refer the solution given below:
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<section>
<div>
<label>
State</label>
<label class="select">
<asp:DropDownList ID="ddlState" runat="server" DataTextField="StateName" DataValueField="StateName">
</asp:DropDownList><i></i>
</label>
</div>
</section>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlCountry" />
</Triggers>
</asp:UpdatePanel>
<div>
<label>
Country</label>
<label class="select">
<asp:DropDownList ID="ddlCountry" runat="server" ToolTip="Select country" DataTextField="CountryName"
DataValueField="CountryID" AutoPostBack="true" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" OnClientClick="ShowCountryLabel();">
</asp:DropDownList><i></i>
<asp:Label ID="lblSelectCountryFirst" Text="Please Select Country" runat="server" ForeColor="Red" style="Display: none;"></asp:Label>
</label>
</div>
</section>
//Jquery Code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function ShowCountryLabel(){
$("#lblSelectCountryFirst").show();
__doPostBack('__Page', '');
}
</script>

Maintian Scrollbar Of GridView Under <div> Asp.netnot working?

i have content page in which i am selecting value from drop down on which gridview populate i am here showing my aspx page,
<div>
<table>
<tr>
<td>
<asp:DropDownList ID="ddlConsultant" runat="server"
AutoPostBack="True"
onselectedindexchanged="ddlConsultant_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td>
</td>
<td>
<asp:TextBox ID="txtActivatedOn" runat="server">
</asp:TextBox>
<a href="javascript:show_calendar('<%=txtActivatedOn.ClientID%>','<%=txtActivatedOn.Text%>');">
<img border="0" src="./Images/calendar.gif" alt="calendar" /></a>
</td>
<td>
</td>
<td>
<asp:Button ID="btnUpdateActivated" runat="server" Text="Update Date"
class="button" />
</td>
</tr>
</table>
<div id="grdWithScroll" style="OVERFLOW: auto" onscroll="SetDivPosition()">
<asp:GridView ID="gvProjects" runat="server" AutoGenerateColumns="False" Height="150px"
Width="225px" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDeleting="gvProjects_RowDeleting"
DataKeyNames="ID" ViewStateMode="Inherit">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chk_All" runat="server" AutoPostBack="true" OnCheckedChanged="chk_All_CheckedChanged"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk_selector" runat="server" AutoPostBack="true" OnCheckedChanged="chk_selector_CheckedChanged" Checked='<%#bool.Parse(Eval("Proj_Flag").ToString() == "True" ? "True": "False") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lbl_ID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ProjectID" Visible="true">
<ItemTemplate>
<asp:Label ID="lblProjectID" runat="server" Text='<%# Bind("ProjectID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%--<asp:TemplateField HeaderText="Order #">
<ItemTemplate>
<!-- <asp:Label ID="lblOrderNumber" runat="server" Text=''></asp:Label>-->
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<a href="javascript:openPopup('DsProjectDetail.aspx?mode=1&cid=<%# Eval("ID") %>&prj=<%#Eval("Title")%>' )">
<%--<%#Eval("Title")%>--%>
<asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label></a>
</ItemTemplate>
<ControlStyle Width="400px" />
</asp:TemplateField>
<%-- <asp:TemplateField HeaderText="CompletionDate">
<ItemTemplate>
<asp:Label ID="lblCompletionDate" runat="server" Text='<%# Bind("CompletionDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="ConsultantID" Visible="false">
<ItemTemplate>
<asp:Label ID="lblConsultantID" runat="server" Text='<%# Bind("CompanyID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField DeleteImageUrl="~/Images/Delete.gif" ButtonType="Image" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</div>
<input type="hidden" id="XPos" runat="server" />
<input type="hidden" id="YPos" runat="server" />
<table>
<tr>
<td>
<asp:Button ID="btnAddProject" runat="server" CssClass="button" Text="New Project"
onclick="btnAddProject_Click" />
</td>
</tr>
</table>
</div>
Javascript i am using are,
<script type="text/javascript">
window.onload = function(){
var strCook = document.cookie;
if(strCook.indexOf("!~")!=0){
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2,intE);
document.getElementById("grdWithScroll").scrollTop = strPos;
}
}
function SetDivPosition(){
var intY = document.getElementById("grdWithScroll").scrollTop;
document.title = intY;
document.cookie = "yPos=!~" + intY + "~!";
}
</script>
<script type="text/javascript">
window.scrollBy(100, 100);
function foo() {
alert("ddd");
if (grdWithScroll != null) alert(grdWithScroll.scrollTop);
}
</script>
and at the end of the page load event i am using,
Page.ClientScript.RegisterStartupScript(GetType(), "MyKey", "SetDivPosition();", true);
i have added this line in
<%# Page Language="C#" MaintainScrollPositionOnPostback="true" ...
and also added in webconfig,
<system.web>
<pages maintainScrollPositionOnPostBack="true" >
</pages>
</system.web>
getting help from this link,
http://stackoverflow.com/questions/12092150/maintain-scroll-bar-position-of-a-div-within-a-gridview-after-a-postback
One think i wanna mention that "onscroll="SetDivPosition()" in div tag showing me warning that on scroll is not valid attribute for div tag
But after doing all this its not working for me firstly i populate gridview with dropdown when grid populate it shows check box column too in all rows that on checked save check box value in database and post back occurs if i am at bottom of grid it scroll to the top after post back
Hopes for your suggestion
Thanks

Auto-select child checkboxes

I've to work with the roles of the users, that I have in a sql base.
Every role has a checkbox, the idea is to check the "childrens" checkboxes if the "parent" is checked, and check the "parent" if all the "childrens" are checked.
I tried this script in a page and it worked, but I can not make this work in my asp.net
This is my script and code.
$(document).ready(function () {
$('.parent').click(function () {
if ($(this).is(':checked'))
$(this).parent().find('.children input[type="checkbox"]').attr('checked', 'checked');
});
$('.children input[type="checkbox"]').click(function () {
var numberOfCheckboxes = $(this).parents('.children').find('input[type="checkbox"]').length;
if ($(this).parents('.children').find('input[type="checkbox"]').filter('input[checked=checked]').length == numberOfCheckboxes)
$(this).parents('div').find('.parent').attr('checked', 'checked');
});
});
<div>
<asp:DataList ID="outerDataList" runat="server" DataSourceID="ObjectDataSource2" >
<ItemTemplate>
<li>
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>'
Visible="False" />
<asp:Label ID="typeLabel" runat="server" Text='<%# Eval("type") %>'
Visible="False" />
<asp:CheckBox ID="chkEnabled" class="parent" runat="server"
Checked='<%# Eval("Enabled") %>' Text='<%# Eval("name") %>' />
</li>
<ul class="children">
<asp:DataList ID="innerDataList" runat="server" DataSource='<%# Eval("Roles") %>'>
<ItemTemplate>
<li>
<asp:Label ID="idLabelInt" runat="server"
Text='<%# Eval("id") %>' Visible="False" />
<asp:Label ID="typeLabelInt" runat="server"
Text='<%# Eval("type") %>' Visible="False" />
<asp:CheckBox ID="chkEnabledInt" runat="server"
Checked='<%# Eval("Enabled") %>' Text='<%# Eval("name") %>' />
</li>
</ItemTemplate>
</asp:DataList>
</ul>
</ItemTemplate>
</asp:DataList>
</div>
Move your list item closing tag to encapsulate the sub-list.
<div>
<asp:DataList ID="outerDataList" runat="server" DataSourceID="ObjectDataSource2" >
<ItemTemplate>
<li>
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>'
Visible="False" />
<asp:Label ID="typeLabel" runat="server" Text='<%# Eval("type") %>'
Visible="False" />
<asp:CheckBox ID="chkEnabled" class="parent" runat="server"
Checked='<%# Eval("Enabled") %>' Text='<%# Eval("name") %>' />
<ul class="children">
<asp:DataList ID="innerDataList" runat="server" DataSource='<%# Eval("Roles") %>'>
<ItemTemplate>
<li>
<asp:Label ID="idLabelInt" runat="server"
Text='<%# Eval("id") %>' Visible="False" />
<asp:Label ID="typeLabelInt" runat="server"
Text='<%# Eval("type") %>' Visible="False" />
<asp:CheckBox ID="chkEnabledInt" runat="server"
Checked='<%# Eval("Enabled") %>' Text='<%# Eval("name") %>' />
</li>
</ItemTemplate>
</asp:DataList>
</ul>
</li>
</ItemTemplate>
</asp:DataList>
</div>
Here, you are looking for descendants of the checkbox's parent with a class of children:
$(this).parent().find('.children input[type="checkbox"]')
As you currently have it, with the <ul> as a sibling of the <li>, rather than a child, this selector doesn't work.
Besides it breaking your selector, it's also invalid HTML. A <li> must be a child of a <ul>, <ol>, or <menu> element. The only allowed children of these elements are <li> elements. (The exception being <menu>, which can alternatively contain flow content instead of <li> elements.) To generate valid HTML, you must replace your parent <div> element with a <ul>, <ol>, or <menu>.
Also, I think you want .closest(), which selects a single element - the first ancestor matching the selector, instead of .parents(), which selects every ancestor matching the selector.

Categories