I have a checkbox list
, this checkbox list is in a modal and populated on page load via SQL Server
Markup
<asp:CheckBoxList ID="myCheckBoxList" runat="server" AutoPostBack="false"></asp:CheckBoxList>
Code Behind
myCheckBoxList.DataSource = rdrMyReader;
myCheckBoxList.DataTextField = "Name";
myCheckBoxList.DataValueField = "Name_ID";
myCheckBoxList.DataBind();
I then have another query that checks the checkboxes on change of another field. So what happens is, when the user chooses a location, it runs an onchange method in the code behind that runs the query to check the appropriate checkboxes. My problem is that the checkbox list has over 100 items in it and it is a bad user experience to have to scroll through the entire list to see what is checked...
I have been trying to filter all checked items to the top of the list, but can not seem to find a way to do this and make it fire on change on the dropdown list
<asp:DropDownList AutoPostBack="true" ID="drpDownLocation" runat="server" CssClass="searchfield form-control" EnableViewState="true" OnSelectedIndexChanged="drpDownLocation_Change">
</asp:DropDownList>
I have tried this, but it is not working for me...
$(function () {
var cbl = $('#myCheckBoxList');
if (cbl.length) {
var cbElements = cbl.find('TR').filter(function (index, element) {
return $(this).find('input:checked').length;
});
cbElements.each(function () {
$(this).prependTo(cbl);
});
}
});
Does anyone have any advice on how I can achieve this?
Aucun commentaire:
Enregistrer un commentaire