如何在c#中打印网格视图 [英] how to print the grid view in c#

查看:88
本文介绍了如何在c#中打印网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private   void  btnprint_Click(对象发​​件人,EventArgs e)
{
printDocument1.Print();



}



  private   void  printDocument1_PrintPage( object  sender,PrintPageEventArgs e)
{
PaintEventArgs myPaintArgs = new PaintEventArgs(e.Graphics, new Rectangle( new 点( 0 0 ), .Size));
this .InvokePaint(dataGridView1,myPaintArgs);
}




$ b $我不能得到我的印刷品和期望的结果......你可以帮助我吗...和代码应该用较少的行....

解决方案

将gridview放在div标签之间并给出div标签的id。



然后放一个打印链接并点击链接调用javascript。在javascript中,通过使用document.getElementById找到div对象并获取div的innerHTML代码,它将给出网格html代码。



然后通过给出这个html使用document.print代码作为内容。这是一个过程,如果您没有获得解决方案,您可以使用谷歌相同。



不要犹豫,请问我是否有任何混淆。


使用此代码:



将此代码放入头部

 <  < span class =code-leadattribute> script     type   =  text / javascript >  
function print( divid)
{
var prtContent = document.getElementById(strid);
var WinPrint;
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
prtContent.innerHTML = strOldOne;
}
< / script >





并将此代码放在正文标签上









在aspbutton上调用javascript函数OnClientClick事件


private void btnprint_Click(object sender, EventArgs e)
        {
            printDocument1.Print();



        }


private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            PaintEventArgs myPaintArgs = new PaintEventArgs(e.Graphics, new Rectangle(new Point(0, 0), this.Size));
            this.InvokePaint(dataGridView1, myPaintArgs);
        }



i cant get my print and with desired results... can u please help me in this.. and the code should be with less lines....

解决方案

Put the gridview between div tag and give id of div tag.

then put a link of print and call a javascript on click of link. in the javascript, find div object by using document.getElementById and get innerHTML code of div it will give grid html code.

Then use document.print by giving this html code as content. This is process or you can use google for the same if you don't get solution.

don't hesitate, pls ask me if there is any confusion.


use this code:

put this code in head section

<script type="text/javascript">
function print(divid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint;
 WinPrint.document.write(prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 prtContent.innerHTML=strOldOne;
}
</script>



and put this code on body tag




call javascript function on aspbutton "OnClientClick" Event


这篇关于如何在c#中打印网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆