Click here to Skip to main content
15,887,291 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have a gridview with paging enabled.when i print the grid data it prints only a particular page data.But what i need is it should print all of the data of all pages.Is it possible?If yes how can i achieve this task.I m stuck.Help me out.


Thanks in advance..
Posted

Yes it is possible to print all data in Gridview

Refer Here:
http://www.aspsnippets.com/Articles/Print-functionality-in-ASP.Net-GridView-control.aspx[^]
 
Share this answer
 
 
Share this answer
 
Comments
Tom Marvolo Riddle 14-Dec-13 7:38am    
@Tadit Dash:Just 14 sec late
Oh yes. :P
protected void btnPrintAllPages_Click(object sender, EventArgs e)


{


GridView1.AllowPaging = 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.AllowPaging = true;


GridView1.DataBind();


}
 
Share this answer
 

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