how to print the gridview of page in require format

11,818

if you want to using javascript so you can try this

function printItn() {
                  //In my case i have append gridview in Panel that y..you can put your contentID which is you want to print.

                    var printContent = document.getElementById('<%= pnlForm.ClientID %>');
                    var windowUrl = 'about:blank';
                    var uniqueName = new Date();
                    var windowName = 'Print' + uniqueName.getTime();

        //  you should add all css refrence for your Gridview. something like.

                    var WinPrint= window.open(windowUrl,windowName,'left=300,top=300,right=500,bottom=500,width=1000,height=500');WinPrint.document.write('<'+'html'+'><head><link href="cssreference" rel="stylesheet" type="text/css" /><link href="gridviewcssrefrence" rel="stylesheet" type="text/css" /></head><'+'body style="background:none !important"'+'>');
                    WinPrint.document.write(printContent.innerHTML);
                    WinPrint.document.write('<'+'/body'+'><'+'/html'+'>');
                    WinPrint.document.close();
                    WinPrint.focus();
                    WinPrint.print();
                    WinPrint.close();
                    }

Hops its helps

Share:
11,818
Prakash Kumar Jha
Author by

Prakash Kumar Jha

Updated on June 04, 2022

Comments

  • Prakash Kumar Jha
    Prakash Kumar Jha almost 2 years

    I have a gridview from database and the issue is i want to print the whole page when the user click the print button each row of gridview print in given format as 3 row on 1 A4 size page.

    gridview enter image description here

    Printing format enter image description here

  • Jignesh Rajput
    Jignesh Rajput about 12 years
    you should try this link..dotnetcurry.com/ShowArticle.aspx?ID=92 or also see this [question]:stackoverflow.com/questions/9561744/… may be help u!!!