Answered by:
How to print All Pages from DetailsVIew in single Click?

Question
-
User-1473011517 posted
I have created web page with DetailsView and want to print all the pages from DetailsView in single click.
Monday, September 5, 2016 12:00 PM
Answers
-
User-1473011517 posted
I m using same code from "Aspsnippets.com" for other pages. And I did Same thing but it did not worked for DetailsView. So Searched lot and lot and lot but didn't find anything so put same code with small change and its working Perfect. You can see as :
protected void PrintAll_Click(object sender, EventArgs e) { Int32 p = DetailsView1.PageIndex; Int32 pc = DetailsView1.PageCount; //Int32 tpc = pc - p; Int32 i; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); for (i = p; i <= pc; i++) { DetailsView1.PagerSettings.Visible = false; DetailsView1.PageIndex = p; DetailsView1.DataBind(); PanelHall.RenderControl(hw); p++; } 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()); }
Before Rendering control change the page index and bind data or else it will render single and last page.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, September 6, 2016 6:28 AM
All replies
-
User36583972 posted
Hi vijaypwr61,
According to your description , When you call the print method, you can modify the AllowPaging property as false, so this can achieve the desired effect.
Sample for your reference :
Print functionality in ASP.Net GridView control :
http://www.aspsnippets.com/Articles/Print-functionality-in-ASP.Net-GridView-control.aspx
Best Regards,
Yohann Lu
Tuesday, September 6, 2016 5:20 AM -
User-1473011517 posted
I m using same code from "Aspsnippets.com" for other pages. And I did Same thing but it did not worked for DetailsView. So Searched lot and lot and lot but didn't find anything so put same code with small change and its working Perfect. You can see as :
protected void PrintAll_Click(object sender, EventArgs e) { Int32 p = DetailsView1.PageIndex; Int32 pc = DetailsView1.PageCount; //Int32 tpc = pc - p; Int32 i; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); for (i = p; i <= pc; i++) { DetailsView1.PagerSettings.Visible = false; DetailsView1.PageIndex = p; DetailsView1.DataBind(); PanelHall.RenderControl(hw); p++; } 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()); }
Before Rendering control change the page index and bind data or else it will render single and last page.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, September 6, 2016 6:28 AM -
User-1473011517 posted
Thank you
Tuesday, September 6, 2016 6:29 AM