Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have been using this code for using button "print all page" in my company e-leave. It is successfull , but when i want to print gridview for filter page it went out to printed the latest record which is not the filter page that i want. How can i print gridview for the filter page? This is my code for C#

C#
<pre>public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }

    protected void OnPaging(object sender, GridViewPageEventArgs e)
    {
        gvTranList.PageIndex = e.NewPageIndex;
        gvTranList.DataBind();
    }


    protected void PrintAllPages(object sender, EventArgs e)
    {
        gvTranList.AllowPaging = false;
        gvTranList.Columns[8].Visible = false;
        gvTranList.Columns[9].Visible = false;
        gvTranList.DataBind();
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        gvTranList.RenderControl(hw);
        string gridHTML = sw.ToString().Replace("\"", "'")
            .Replace(System.Environment.NewLine, "");
        StringBuilder sb = new StringBuilder();
        sb.Append("<script type = 'text/javascript'>");
        sb.Append("window.onload = new function(){");
        sb.Append("var printWin = window.open('', '', 'left=0");
        sb.Append(",top=0,width=1000,height=600,status=0');");
        sb.Append("printWin.document.write(\"");
        sb.Append(gridHTML);
        sb.Append("\");");
        sb.Append("printWin.document.close();");
        sb.Append("printWin.focus();");
        sb.Append("printWin.print();");
        sb.Append("printWin.close();};");
        sb.Append("</script>");
        ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
        gvTranList.AllowPaging = true;
        gvTranList.DataBind();
        gvTranList.Columns[8].Visible = true;
        gvTranList.Columns[9].Visible = false;

    }
}


What I have tried:

Print Current Page and Print All Pages of GridView[^]
Posted

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