þÍńķ
þÍńķ

Reputation: 363

How to set Dynamic id for <tr> of a Gridview in Jquery.?

Iam having a Gridview which loads dynamically

I have check box in that GridView . I just wanted to check if Two or More checkboxs are checked, i think i can check that by knowing the class of

Here is my Gridview which loads Dynamically using Jquery

   success: function (JSONData) {
            try {
                var oPorts = $.parseJSON(JSONData.d);
                for (var i = 0; i < oPorts.length; i++) {

                    var text = "<tr><td>" + '<input id="gvChk" class="gvChk" type="checkbox">' + "</td><td>" + oPorts[i].TerminalName + "</td></tr>"; 
                   // Want to know How many check boxes are checked

                    $('.iframe').contents().find('.gvPorts').append(text);
                }
            }

SUppose iam getting 5 records to the GridView i want to check for that condition of more IF than 2 checks, When i check in browser for class for / there is NO class

This Grid view is Dynamic, SO how should i check for Input Checkbox selection Count? Any help is very thankful.

Upvotes: 0

Views: 454

Answers (1)

Paras
Paras

Reputation: 3067

If you want to know the number of checkbox checked before you bind the elements to the dom, you need to check that from one of the variables that comes from the json data e.g.

oPorts[i].IsChecked

and you can count the number of checked values.

The other way would be to bind it in dom and check. Example is shown in this fiddle

 var oPorts = [0,1,2,3,4]

                for (var i = 0; i < oPorts.length; i++) {

                    var text = "<tr><td>" + '<input id="gvChk" class="gvChk" type="checkbox">' + "</td><td>" + oPorts[i] + "</td></tr>"; 


                    $('.gvPorts').append(text);
                }
$('.gvPorts input[type="checkbox"]').on("change",function(){
    alert($('.gvPorts input:checked').length);
});

Upvotes: 1

Related Questions