打印Gridview并启用分页 [英] Print Gridview with paging enabled

查看:84
本文介绍了打印Gridview并启用分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Print Helper打印面板

和btn点击我的代码是:



I use Print Helper to print panel
and on btn click my code is:

protected void btnPrint_Click(object sender, EventArgs e)
{
    grd.AllowPaging=false;
    bindgrid();
    Session["ctrl"] = pnlPrint;
    ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('Print.aspx','PrintMe','height=500px,width=800px,scrollbars=1');</script>");
    grd.AllowPaging=true;
    bindgrid();
}



其中pnlPrint是aspPanel的id。







我的问题是:

点击打印按钮时打印页面上也会显示打印。

只有页面内容打印在纸上


where pnlPrint is the id of aspPanel.



my Problem is that:
when click on print button the pagging is also displayed on the print page.
and only that page contents are printed on the paper

推荐答案

当您在基于Web的应用程序上启用分页时,在任何给定时间只有一个页面在客户端上 - 它在发出下一个按钮之前不会转移下一页。



这意味着您无法通过此方法打印多个页面。您需要刷新包含网格的页面以获取所有数据。
When you enable paging on a web based application, only one page is on the client at any given time - it doesn't transfer the next page until the "next" button is instigated.

This means you cannot print more than one page by this method. You would need the page containing the grid to be refreshed to get all the data.


在打印按钮点击事件中使用下面的代码





use below code in print button click event


grd.AllowPaging = false;
     bindgrid();
      StringWriter sw = new StringWriter();
      HtmlTextWriter hw = new HtmlTextWriter(sw);
      grd.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());
      grd.AllowPaging = true;
      bindgrid();







和ad d以下事件也对CS页面






and add below event also to CS Page

public override void VerifyRenderingInServerForm(Control control)
{
    /* Verifies that the control is rendered */
}







如果它解决了您的问题接受解决方案




If it solves your problem accept solution


这篇关于打印Gridview并启用分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆