Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a customer details table which having 56 columns.
I display some rows in GridView.
When I print the data from GridView it only printing starting 12 columns; all remaining columns data cutting off.

I want two solution
Either
1) Print all columns in anyhow condition on single page (Landscape/portrait mode) no matter if data is readable or not
OR
2) Whatever cut data must be print on second page.


Here is my HTML code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css" media="print">
div {
float :none;
display: block;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="AuditPlanId" DataSourceID="SqlDataSource1">

//my columns list (59 columns)

</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EX %>" SelectCommand="SELECT TOP 100 * FROM [MstrAuditPlan]"></asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>


and for Print on PrintBtn_Click
C#
GridView1.PagerSettings.Visible = false;
            GridView1.DataBind();
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.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());
            GridView1.PagerSettings.Visible = true;
            GridView1.DataBind();


What I have tried:

<style type="text/css" media="print">
div {
float :none;
display: block;
}
</style>
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