Check/Uncheck exclusively boxes in WebForms CheckBoxList

//Tailored for ASP.Net WebForms CheckBoxList control //Checks/unchecks a list of checkboxes depending of what is checked //If the first item "All" is checked, uncheck everything else. If any item except "All" is checked, uncheck "All" //JavaScript function handleCheckBoxList(idLst, element) { if (element.checked) { if (element.id.endsWith("_0")) { //Uncheck everything except "All" $("input[id*='" + idLst + "']").not("input[id$='" + idLst + "_0']").prop('checked', false); } else { //Uncheck "All" $("input[id$='" + idLst + "_0']").prop('checked', false); } } } //ASP.Net : databound list, with the first item being "All" <asp:CheckBoxList runat="server" ID="_lstBoxes"></asp:CheckBoxList> //Code-behind foreach (ListItem item in _lstBoxes.Items) { item.Attributes.Add("onclick", "handleCheckBoxList('" + _lstBoxes.ID + "',this)"); }
Tailored for ASP.Net WebForms CheckBoxList control
Checks/unchecks a list of checkboxes depending of what is checked
If the first item "All" is checked, uncheck everything else.
If any item except "All" is checked, uncheck "All"

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.