Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
function GetSelectedRow(e) {
        var clickedRow = $(e).closest("tr");
        var id = $(clickedRow).find('td').eq(0).text();
        var gvcheck = document.getElementById('<%=dgv_Modules.ClientID %>');
        var chklist = gvcheck.getElementsByTagName('input');
        for (var i = 0; i < chklist.length; i++) {
            if (chklist[i].prop("checked",true)) {
                alert("c");
            }
        }
        return false;
    }



I have used prop() but its not working
chklist is checkbox
Posted

there are several way :

var isChecked = $("input:checked").length > 0
var isChecked = $("input").is(':checked')
var isChecked = $("input").prop('checked')
var isChecked = $("input").attr("checked") === "checked" // WRONG (dows not change if you check/unckeck it)

and a lot more.

i prefer the second way, it is a lot easier to read

read more about them here http://api.jquery.com/prop/[^]



NOTE : your .prop("checked",true) is a SETTER, you are checking the checkbox, the GETTER has no value (omit the true)
 
Share this answer
 
v3
C#
function GetSelectedRow(e) {
       var clickedRow = $(e).closest("tr");
       var id = $(clickedRow).find('td').eq(0).text();
       var gvcheck = document.getElementById('<%=dgv_Modules.ClientID %>');
       var chklist = gvcheck.getElementsByTagName('input');
       for (var i = 0; i < chklist.length; i++) {
           if ($(chklist[i]).prop("checked")) {
               var checkedrowid = $(chklist[i]).find('td').eq(0).text();
           }
       }
       return false;
   }
 
Share this answer
 

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