asp.net - Check if asp Checkbox is checked in a row of a GridView with Javascript -
i have grid view , want see if checkbox in first column checked. if check box checked opens new window. cannot figure out how see if checkbox checked. please function below not working , can't figure out why.
function mapselectedclick() { var customerids = ""; var grid = document.getelementbyid('<%=grdcustomers.clientid %>'); (var = 1; < grid.rows.length; i++) { var row = grid.rows[i]; var customerid = grid.rows[i].cells[1].innertext; if (grid.rows[i].cell[0].type == "checkbox") { if (grid.rows[i].cell[0].childnodes[0].checked) { customerids += customerid.tostring() + ','; } } } customerids = customerids.substring(0, customerids.length-1); window.open("mapcustomers.aspx?customerids=" + customerids); }
there few problems in code:
- in both
ifconditions, usedcell[0]instead ofcells[0] - in outer
ifcondition usedcell[0].type == "checkbox". cell can't have type checkbox, includeschekboxcontrol child
modify function this:
function mapselectedclick() { var customerids = ""; var grid = document.getelementbyid('<%=grdcustomers.clientid %>'); (var = 1; < grid.rows.length; i++) { var row = grid.rows[i]; var customerid = row.cells[1].innertext; var ctrl = row.cells[0].childnodes[0]; if (ctrl.type == "checkbox") { if (ctrl.checked) { customerids += customerid.tostring() + ','; } } } customerids = customerids.substring(0, customerids.length-1); window.open("mapcustomers.aspx?customerids=" + customerids); } note innertext not cross browser compatible, use innerhtml wherever possible.
Comments
Post a Comment