Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void btnprint_Click(object sender, EventArgs e)
        {
            printDocument1.Print();



        }

C#
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....
Posted
Comments
CHill60 26-Jun-14 8:25am    
What do you mean "with desired results" - does it print or not? And "less lines" than what? You haven't exactly got a lot of lines of code here!
Thanks7872 26-Jun-14 8:51am    
:laugh:

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.
 
Share this answer
 
use this code:

put this code in head section
XML
<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
 
Share this answer
 
Comments
navya chowdary 26-Jun-14 23:48pm    
i want code in c# windows froms

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900