在pagerdatasource中禁用分页并打印gridview的所有行 [英] Disable paging in pagerdatasource and print all rows of gridview
本文介绍了在pagerdatasource中禁用分页并打印gridview的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个绑定到pagerdatasource的gridview。我在打印所有网格行时遇到问题。当我尝试打印gridview时,它只打印grid的第一页。我从后面的代码打印gridview。 />
i尝试了以下内容
I have a gridview which is binded to a pagerdatasource.I m facing problems in printing all rows of grid.When i try to print gridview it prints only the first page of grid.I m printing gridview from code behind.
i have tried the following
protected void btnPrint_Click(object sender, EventArgs e)
{
GridView1.UseAccessibleHeader = true;
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
FillGrid();
pds.AllowPaging = false;
this.GridView1.ShowFooter = true;
// GridView1.Attributes["style"] = "border-collapse:separate";
foreach (GridViewRow row in GridView1.Rows)
{
//row.Attributes["style"] = "border-top-style:none; border-bottom-style:solid; border-left-style:none; border-right-style:none; border-color:Black;";
if (row.RowIndex % 20 == 0 && row.RowIndex != 0)
{
row.Attributes["style"] = "page-break-after:always;";
}
}
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(\"");
string style = "<style type = 'text/css'>thead {display:table-header-group;} tfoot{display:table-footer-group;}</style>";
sb.Append(style + gridHTML);
sb.Append("\");");
sb.Append("printWin.document.close();");
sb.Append("printWin.focus();");
sb.Append("printWin.print();");
sb.Append("printWin.close();");
sb.Append("};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
FillGrid();
pds.AllowPaging = true;
//GridView1.DataSource = pds;
//GridView1.DataBind();
}
但它不打印所有行。请帮助..
But its not Printing all rows.Please help..
推荐答案
看看这里的伙伴,
http://www.aspsnippets.com/Articles/Print-functionality-in-ASP.Net-GridView- control.aspx [ ^ ]
打印GridView分页 [ ^ ]
第一个是太棒了;-)
-KR
Take a look here mate,
http://www.aspsnippets.com/Articles/Print-functionality-in-ASP.Net-GridView-control.aspx[^]
Printing a GridView with Paging[^]
First one is quite awesome ;-)
-KR
这篇关于在pagerdatasource中禁用分页并打印gridview的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文