Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to Print all pages of gridview while paging is enabled.
Posted
Updated 10-Nov-11 0:27am
v2
Comments
Prerak Patel 10-Nov-11 6:22am    
Didn't you solve it there in your previous question?

follow the link.. few good articles.. hope your problem will be resolved soon...

http://www.aspsnippets.com/Articles/Print-functionality-in-ASP.Net-GridView-control.aspx[^]


Printing a GridView with Paging[^]



mark as answer if solves your problem.
 
Share this answer
 
v2
 
Share this answer
 
Comments
P.Salini 10-Nov-11 6:50am    
My 5!
RaviRanjanKr 10-Nov-11 6:54am    
Thanks :)
 
Share this answer
 
i have tried that one, like this but not working

protected void btnPrint_Click(object sender, EventArgs e)
{
int count = GridView1.PageCount;
if (count == GridView1.PageIndex + 1)
{
GridView1.EmptyDataRowStyle.Font.Bold = true;
GridView1.FooterRow.Visible = true;
}
else
{
GridView1.FooterRow.Visible = false;
}
//GridView1.PagerSettings.Visible = false;
GridView1.AllowPaging = false;
//GridView1.BottomPagerRow.Visible = false;
GridView1.FooterRow.Font.Bold = true;
Response.Write("<script>window.print();</script>");
BindGrid();
GridView1.AllowPaging = true;
}
once finally i set as true, paging shown in the printing time also..
please post any help
 
Share this answer
 
protected void PrintAllPages(object sender, EventArgs e)
        {
            GridView1.AllowPaging = false;
            GridView1.DataBind();
            GridView1.HeaderRow.Cells[9].Visible = false;
            GridView1.FooterRow.Cells[9].Visible = false;
            // Loop through the rows and hide the cell in the first column
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                GridViewRow row = GridView1.Rows[i];
                row.Cells[9].Visible = false;
            }
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            hw.AddStyleAttribute(HtmlTextWriterStyle.Direction, "rtl");
            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.AllowPaging = true;
            GridView1.DataBind();
        }
        protected void PrintCurrentPage(object sender, EventArgs e)
        {
            
            GridView1.PagerSettings.Visible = false;
            GridView1.DataBind();
            GridView1.HeaderRow.Cells[9].Visible = false;
            GridView1.FooterRow.Cells[9].Visible = false;
            // Loop through the rows and hide the cell in the first column
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                GridViewRow row = GridView1.Rows[i];
                row.Cells[9].Visible = false;
            }
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            hw.AddStyleAttribute(HtmlTextWriterStyle.Direction, "rtl");
            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();
        }
 
Share this answer
 
Comments
Richard Deeming 11-Mar-15 14:51pm    
You've been here nearly five years - long enough to know how we feel about people resurrecting old questions.

This question was posted over three years ago.
Member 11226668 25-Nov-18 5:31am    
Do you really think that if something is already answered by someone then the thread should be given Nobel prize and close it forever. And no better solution can come in future while IT life is so dynamic.

FYI I got benefited today by that ans. I know you posted it 3 years back but i am posting this reply for others who reply quickly to discourage people :)

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