-1

I have one asp.net data table control. in every <td> tag I have images with checkboxes.

$("#gvDetails").empty();
$.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "gallries.aspx/BindDatatable",
        data: "{'blouseType':'" + blouseType + "'}",
        dataType: "json",
        success: function (data) {
            var el = "<tr>";
            for (var i = 0; i < data.d.length; i++) {
                var discript = data.d[i].FrontImage;
                if (i % 3 == 0) {
                    el += "</tr><tr>"
                }
                var price = data.d[i].Price;
                el += "<td style='padding:10px 40px 10px 40px'><div><a id='link" + data.d[i].ImageId + "' class='example-image-link' href='#myPopup' data-rel='popup' data-position-to='window' alt='LightBox'><img class='example-image' src=" + data.d[i].FrontImage + " width='150px' height='218px'/></a></div></br>";
                el += "<span style='bottom: 6px;'><input name='subscribe' type='checkbox' class='myCheck' value=''></input></span><div><label style='font-size: x-small;'>" + price + "</label></div><a href='http://www.google.co.in'><img src='images/pint.jpg' alt='' width='15' height='11'></a><a href='http://www.google.co.in'><img src='images/fb.png' alt='' width='15' height='11'></a><span id='imgId' style='display: none;'>" + data.d[i].ImageId + "</span></td>";
 }
                el += '</tr>';
                $("#gvDetails").append($(el));
            },
            error: function (result) {
                    alert("Error");
            }
        });
    }

So whenever I am checking any check box then those image database table's image ids saving in faverite table.so I want to check the check boxes which I was selected images? so How to check the check boxes by those image ids which i am getting from database

<script type="text/javascript">
        $(document).ready(function () {
            $(document).on("change", "[class*=myCheck]", function () {
                var userCookie = getCookie('loggedInUser');
                function getCookie(name) {
                    var nameEQ = name + "=";
                    var ca = document.cookie.split(';');
                    for (var i = 0; i < ca.length; i++) {
                        var c = ca[i];
                        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
                        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
                    }
                    return null;
                }

                var userIdCookie = getCookie('loggedUserId');
                function getCookie(name) {
                    var nameEQ = name + "=";
                    var ca = document.cookie.split(';');
                    for (var i = 0; i < ca.length; i++) {
                        var c = ca[i];
                        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
                        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
                    }
                    return null;
                }

                var imageId = $(this).closest("td").find('#imgId').html();
                if (this.checked) {
                    if (userCookie != null) {
                        $.ajax({
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            url: "gallries.aspx/insertgalImage",
                            data: "{'imgId':'" + imageId + "','userId':'" + userIdCookie + "','methode':'insertion'}",
                            dataType: "json",
                            success: function (popup) {
                                alert(popup.d);
                            },
                            error: function (result) {
                                alert("Error");
                            }
                        });
                    }
                    else {
                        $('#modal_trigger')[0].click();
                        $(this).prop("checked", false);
                    }
                }
                else {
                    alert('Hello Checked');
                    alert(imageId);
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "gallries.aspx/insertgalImage",
                        data: "{'imgId':'" + imageId + "','userId':'" + userIdCookie + "','methode':'deletion'}",
                        dataType: "json",
                        success: function (popup) {
                            alert(popup.d);
                        },
                        error: function (result) {
                            alert("Error");
                        }
                    });
                }
            });
        });
        </script>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
asma
  • 75
  • 9

1 Answers1

0

like below I was seeking..now I got the answer after much struglled.

if (userIdCookie != null) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "gallries.aspx/favoriteData",
                    data: "{userLoggedInId : '" + userIdCookie + "'}",
                    dataType: "json",
                    success: function (checkBoxesData) {
                        for (var i = 0; i < checkBoxesData.d.length; i++) {
                            var GallryImageId = checkBoxesData.d[i].favoriteImageIds;
                            $(".gallImageIds").map(function () {                                
                                var spanImgId = $(this).text();
                                if (GallryImageId == spanImgId) {
                                    $(this).closest('td').find('[type=checkbox]').prop('checked', true);
                                }
                            });
                        }

                    },
                    error: function (result) {
                        alert("Error");
                    }
                });
asma
  • 75
  • 9