printing gridview

Discussion in 'ASP .Net' started by =?Utf-8?B?Vmlua2k=?=, Oct 26, 2007.

  1. Hello Everyone,

    I am trying to print a gridview. I have a print button on my aspx page.
    Below is the javascript code

    function CallPrint( strid )
    {
    var prtContent = document.getElementById( strid );
    var WinPrint = window.open('', '',
    'left=0,top=0,width=1050,height=600,toolbar=1,scrollbars=1,status=0');
    WinPrint.document.write( prtContent.innerHTML );
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close();
    // prtContent.innerHTML=strOldOne;
    }

    <asp:Button ID="btnPrint" runat="server" Text="Print the Grid"
    OnClick="btnPrint_Click" Style="position: static" />

    Inside the aspx.cs page, i have
    btnPrint.Attributes["onclick"] = "javascript:CallPrint('print_Grid');";

    and my gridview is inside the <div> tag

    <div id="print_Grid">
    gridview - that needed to be printed

    </div>

    I have two questions:

    1) I can print the grid view but not all the columns are coming in the
    printout. Last 10 columns of the aspx screen are cutoff from the printout. Is
    it possible to printout and see all the columns. I tried landscpae view, but
    still all the columns are not coming in the print out.
    2) can I get the header of the gridview in every printout.

    Please let me know if it possible

    Thanks.
    =?Utf-8?B?Vmlua2k=?=, Oct 26, 2007
    #1
    1. Advertising

  2. Vinki,

    Printing a gridView from an ASP .net page can become a nightmare. I would
    rather let the user export the grid into excel so he can configure the output
    using a powerful Office product like Ms Excel.

    A fast way to export a grid view to Excel (no extra code from your side
    needed, just use this free source code):

    http://www.dotnetjohn.com/articles.aspx?articleid=231

    Good luck,
    Braulio

    PS: More info about ASP .net and Excel Export:

    http://www.tipsdotnet.com/ArticleBlog.aspx?KWID=51&Area=Excel&PageIndex=0

    More info about ASP .net Gridview:

    http://www.tipsdotnet.com/ArticleBlog.aspx?KWID=3&Area=GridView&PageIndex=0

    /// ------------------------------
    /// Braulio Diez
    ///
    /// http://www.tipsdotnet.com
    /// ------------------------------




    "Vinki" wrote:

    > Hello Everyone,
    >
    > I am trying to print a gridview. I have a print button on my aspx page.
    > Below is the javascript code
    >
    > function CallPrint( strid )
    > {
    > var prtContent = document.getElementById( strid );
    > var WinPrint = window.open('', '',
    > 'left=0,top=0,width=1050,height=600,toolbar=1,scrollbars=1,status=0');
    > WinPrint.document.write( prtContent.innerHTML );
    > WinPrint.document.close();
    > WinPrint.focus();
    > WinPrint.print();
    > WinPrint.close();
    > // prtContent.innerHTML=strOldOne;
    > }
    >
    > <asp:Button ID="btnPrint" runat="server" Text="Print the Grid"
    > OnClick="btnPrint_Click" Style="position: static" />
    >
    > Inside the aspx.cs page, i have
    > btnPrint.Attributes["onclick"] = "javascript:CallPrint('print_Grid');";
    >
    > and my gridview is inside the <div> tag
    >
    > <div id="print_Grid">
    > gridview - that needed to be printed
    >
    > </div>
    >
    > I have two questions:
    >
    > 1) I can print the grid view but not all the columns are coming in the
    > printout. Last 10 columns of the aspx screen are cutoff from the printout. Is
    > it possible to printout and see all the columns. I tried landscpae view, but
    > still all the columns are not coming in the print out.
    > 2) can I get the header of the gridview in every printout.
    >
    > Please let me know if it possible
    >
    > Thanks.
    >
    >
    >
    >
    >
    >
    >
    >
    =?Utf-8?B?QnJhdWxpbyBEaWV6?=, Oct 26, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon B
    Replies:
    7
    Views:
    7,498
    =?Utf-8?B?SmFzb25DaG9p?=
    Jan 30, 2006
  2. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    17,958
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  3. JustSomeGuy
    Replies:
    13
    Views:
    506
    msalters
    Dec 9, 2004
  4. iffy agbim
    Replies:
    1
    Views:
    105
    Mark Andrews
    May 24, 2004
  5. iffy agbim
    Replies:
    0
    Views:
    101
    iffy agbim
    May 21, 2004
Loading...

Share This Page