I have a GridView control on my page, and want to loop through the rows and move the data to a window for printing. But I can’t reference the GridView in JavaScript.
In my .aspx:
<input type="button" value="Print" onclick="JavaScript:PrintClaimsTab()" />
In my .js file:
PrintClaimsTab()
{
.
var tableElement = document.getElementById("GridViewClaims");
for (var i=0;i < tableElement.rows.count; i++) {
var rowElem = tableElement.rows[i];
var tablerow = '<tr>';
for (var x=0;x < rowElem.cells.count;x++) {
var cell = rowElem.cells[x];
tablerow = tablerow + '<td>' + cells[x].value + '</td>';
}
tablerow = tablerow + '</tr>';
printWindow.document.write(tablerow);
}
}
But tableElement is always null.
I have also tried:
<input type="button" value="Print" onclick="JavaScript:PrintClaimsTab(<%=GridViewClaims.ClientID%>)" />
And PrintClaimsTab(GridViewID) { var tableElement = document.getElementById(GridViewID); }
In which tableElement is also null.
A different function, which refers to a div, sets tableElement correctly. Any ideas?