Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
i have a table in my view. which is bind data by jquey. I have a checkbox column in my table. which have unique Id foe each row. i have paging in my table. now my problem is when i checked some record and go to another page and checked some record here. now when i back to my previous page check box not checked.
my code is
C#
//for getting checked id
 function GetCheckedRecord() {
        var Ids = $('input[name=chkres]:checked').map(function () {
            return $(this).val();
        }).toArray();
        if (checkval.length > 0) {          
            checkval = checkval + ',' + Ids;
        }
        else {
            checkval = Ids;
        }
       // alert(checkval);
    }

// now click on prev button
 $(".prevPageBtn").on("click", function (e) {
            e.preventDefault();
            GetCheckedRecord();
 $('input[name=chkres]').map(function () {
                var a = ($.inArray($(this).val(), checkval) != -1);               
                $(this).prop("checked", a);
            });
            fetchData(page - 1);                      
        });

//  fetchData(page - 1); is a function which bind data in to table

function fetchData(whichPage)
    {
 var request = $.ajax({          
            url: '@Url.Action("GetJsonResult", "myController")',
            method: "POST",
            data: { "page": whichPage }
        });

        request.done(function (data) {
$.each(data, function (key, val) {
                var today = new Date();
                var bgClass = (key % 2 == 0) ? "search-result-bg" : "";
                var item = '<tr class="' + bgClass + '">';
                item += '<td width="15"><input type="checkbox" id=' + val["RecordID"] + ' value=' + val["RecordID"] + ' name="chkres" class="chkres" /> </td>';
                item += '<td >' + val["RecordID"] + '</td>';
 item += '</tr>';
                items.push(item);
            });
var result = '<div id="loadingOverlay"></div><tr class="search-result-heading">';
                result += '<td width="15">Select All<br/><input class=' + 'check_all' + ' type="checkbox" /></td>';
                result += '<td >RecordId</td>';
 result += '</tr>';
                result += items.join("");
                $("#dtsResult").html(result);
            } });} 
the problem is  <pre lang="c#">$('input[name=chkres]').map(function () {var a = $(this).val();}
show last pages id's of check box.
Posted
Updated 2-Dec-15 21:42pm
v3

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