asp.net - Get the value of a hidden column in a gridview with javascript -
i have function (below) works wonderful need hide column 'customerid' gives me value var customerid = grid.rows[i].cells[1].innertext; if hide column function no longer works works it's grabbing wrong value. can this?
the hidden field looks this...
<asp:templatefield> <itemtemplate> <asp:label id="lblcustomerid" runat ="server" text='<%# eval("customerid")%>'/> </itemtemplate> </asp:templatefield> function:
function mapselectedclick() { var customerids = ""; var grid = document.getelementbyid('<%=grdcustomers.clientid %>'); var count = 0; (var = 1; < grid.rows.length; i++) { var cell = grid.rows[i].cells[0]; var customerid = grid.rows[i].cells[1].innertext; (var j = 0; j < cell.childnodes.length; j++) { if (cell.childnodes[j].type == "checkbox") { if (cell.childnodes[j].checked) { customerids += customerid.tostring() + ','; count++; } } } } if (count == 0) { alert("please select @ least 1 customer map."); return false; } customerids = customerids.substring(0, customerids.length-1); window.open("mapcustomers.aspx?customerids=" + customerids); }
i think better add value="<%# eval("customerid")%>" checkbox.
and use like:
if (cell.childnodes[j].type == "checkbox") { if (cell.childnodes[j].checked) { customerids += cell.childnodes[j].value.tostring() + ','; count++; } } or use same name checkboxes:
<input type="checkbox" name="checkedcustomers" value="1" /> <input type="checkbox" name="checkedcustomers" value="3" /> in js:
var checkedcustomers = document.getelementsbyname("checkedcustomers"); var customerids = []; (var = 0; < checkedcustomers.lenght; i++) { if(checkedcustomers[i].type === 'checkbox' && checkedcustomers[i].checked) customerids.push(checkedcustomers[i].value); } var result = customerids.join(',');
Comments
Post a Comment