Click here to Skip to main content
15,886,063 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
ASP.NET
<itemtemplate>

<asp:checkbox1 runat="server" id="checkbox1" >

<asp:checkbox1ist runat="server" id="cbCollectFor" >

</itemtemplate>

JavaScript
$("[id*=chkOption1]").on("click", function () {
 
            $.ajax({
                type: "POST",
                url: "AdminInitiateCollection.aspx/GetCollectionAreas",
                data: '{}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    //alert(response.d);
                }
            });
        });
 
        function OnSuccess(response) {
 

            var chkOption1 = $(this);
            var grid = $(this).closest("table");
 
            var dtcollection = response.d; // Here my output is [ hard disk, hello, collection ]

           
            var ddCollection = dtcollection.split(",");
        
            
            var $ctrls = $("#<%=gvInitiateCollection.ClientID%> tr input[id*='cbCollectFor']");
            alert($ctrls);
           
                for (var i = 0; i < ddCollection.length; i++) {
                 
 
                    var isChecked = $("#<%=gvInitiateCollection.ClientID%> tr input[id*='chkOption1']").is(":checked");
                    if (isChecked) {
                       
                        $ctrls.find('label:contains("' + ddCollection[i] + '")').prev().prop('checked', true);
                       
                    } else {
                        $(this).removeAttr("checked");
                        $("td", $(this).closest("tr")).removeClass("selected");
                        $ctrls.find('label:contains("' + ddCollection[i] + '")').prev().prop('checked', false);
                       
                    }
                }
            //});

        }


What I have tried:

I am getting error from this line.
JavaScript
var $ctrls = $("#<%=gvInitiateCollection.ClientID%> tr input[id*='cbCollectFor']");
alert($ctrls);
Posted
Updated 12-Apr-16 21:27pm
v2
Comments
Sinisa Hajnal 13-Apr-16 2:42am    
What error?

in your template, there is checkbox1 and in your first query, you try to get chkOption1... Could that be the cause?
kumar2233 13-Apr-16 2:48am    
actual checkbox name is chkoption1.

var $ctrls = $("#<%=gvInitiateCollection.ClientID%> tr input[id*='cbCollectFor']");

<itemtemplate>

<asp:checkbox1 runat="server" id="checkbox1" >

<asp:checkbox1ist runat="server" id="cbCollectFor" >


i'm getting problem at that line ctrls. [object object].
Sergey Alexandrovich Kryukov 13-Apr-16 8:29am    
What would you possibly mean by finding id? Why all this code dump?
—SA

1 solution

Can you share me the link, wherever this code is running. I can help you debug the jquery code, in that way you can find the id or any control.
 
Share this answer
 
v2

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