Click here to Skip to main content
15,887,369 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have check box list and a check box, After binding the data to the checkbox, if we select the all checkboxes then the main checkbox gets selected its fine till now but when we unselect any check box in checkbox list and clicks a button then all checkboxes in the checkboxlist getting unchecked.


How to Hold the checked items of the checkbox list even after the post back.

Javascript code
C#
function pageLoad(sender, args) {
               
               CheckAllProject();
           }


C#
function CheckAllProject () {

               $("[id*=lbxProjectList]").focus(function () {
                    if ($("[id*=lbxProjectList] input:checked").length == $("[id*=lbxProjectList] input").length) {
                        $("[id*=CheckBox1]").attr("checked", "checked");
                    } else {
                        $("[id*=CheckBox1]").removeAttr("checked");
                    }
            });
           }







It Looks like in the following way

Project List:CheckBox Select All Projects
Checkbox 1 Project1
Checkbox 2 Project2


Button Submit
Posted
Comments
Laiju k 6-Nov-14 6:37am    
there is only one button
santoshkumar413 6-Nov-14 7:03am    
Yeah there is only one button.
Laiju k 6-Nov-14 7:32am    
If it is a submit button,then why you need previous values.

1 solution

Here you are calling CheckAllProject() in PageLoad() ,so every time page gets loaded it resets all checkboxes. So instead of calling CheckAllProject() inside PageLoad(),call it in Onclick() of button.
 
Share this answer
 
Comments
santoshkumar413 6-Nov-14 7:05am    
@Pravuprasad, Hi, Thanks for the reply, but the check all checkbox gets check only on the checking of all checkboxes, not by the button click. Please suggest me any other solution.
Pravuprasad 6-Nov-14 7:24am    
use jquery for this in jquery use prop().
i.e
function CheckAllProject () {
$(".class of your checkbox").prop('checked', true);
})
and call it on button click event of Button.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900