更新时间:2023-10-04 08:49:04
请看下面的解决方案
< script type = text / javascript>
function printGrid(){
var gridData = document .getElementById(' <%= GridView1.ClientID%> ;'跨度>);
var windowUrl = ' 约:空白'跨度>;
// 为gridview设置打印文档名称
var uniqueName = new Date ();
var windowName = ' Print _' + uniqueName.getTime();
var prtWindow = window .open(windowUrl,windowName,
' left = 100,top = 100,right = 100,bottom = 100,width = 700,height = 500' )
prtWindow。 document .write(' < html>< head>< / head>');
prtWindow。 document .write(' < ; body style =background:none!important>');
prtWindow。 document .write(gridData.outerHTML);
prtWindow。 document .write(' < ; /体>< / HTML>'跨度>);
// 弹出窗口行
var rows = prtWindow。 document .getElementById(' <%= GridView1.ClientID%>')。rows;
for ( var i = 0 ; i< rows.length; i ++){
// 删除第一列
rows [i] .deleteCell( 0 );
}
prtWindow。 document .close();
prtWindow.focus();
prtWindow.print();
prtWindow.close();
}
您可以参考以下链接隐藏列仅打印Gridview的选定列 [ ^ ]
my javascript code -
<script type="text/javascript">
function printGrid() {
var gridData = document.getElementById('<%=GridView1.ClientID %>');
var windowUrl = 'about:blank';
//set print document name for gridview
var uniqueName = new Date();
var windowName = 'Print_' + uniqueName.getTime();
var prtWindow = window.open(windowUrl, windowName,
'left=100,top=100,right=100,bottom=100,width=700,height=500');
prtWindow.document.write('<html><head></head>');
prtWindow.document.write('<body style="background:none !important">');
prtWindow.document.write(gridData.outerHTML);
prtWindow.document.write('</body></html>');
prtWindow.document.close();
prtWindow.focus();
prtWindow.print();
prtWindow.close();
}
</script>
plz help how to hide 1st column in gridview..........
Please have a look into below solution<script type="text/javascript"> function printGrid() { var gridData = document.getElementById('<%=GridView1.ClientID %>'); var windowUrl = 'about:blank'; //set print document name for gridview var uniqueName = new Date(); var windowName = 'Print_' + uniqueName.getTime(); var prtWindow = window.open(windowUrl, windowName, 'left=100,top=100,right=100,bottom=100,width=700,height=500') prtWindow.document.write('<html><head></head>'); prtWindow.document.write('<body style="background:none !important">'); prtWindow.document.write(gridData.outerHTML); prtWindow.document.write('</body></html>'); //get pop up window rows var rows = prtWindow.document.getElementById('<%=GridView1.ClientID %>').rows; for (var i = 0; i < rows.length; i++) { // remove first column rows[i].deleteCell(0); } prtWindow.document.close(); prtWindow.focus(); prtWindow.print(); prtWindow.close(); }
You can refer following link to hide the columns Printing only selected colums of Gridview[^]