在网格视图中打印所有页面 [英] print all pages in grid view

查看:70
本文介绍了在网格视图中打印所有页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主页面中有gridview控件我使用项目模板在网格视图中绑定数据,

i启用了分页,当我点击打印按钮时它只打印当前页面我要打印所有10页一次如何做到这一点我用这个代码打印,但它不工作可以任何人帮助我..提前感谢





  public  覆盖  void  VerifyRenderingInServerForm(控制控件)
{
/ * 验证控制被渲染* /
}


受保护 void PrintAllPages( object sender,EventArgs e)
{
GridView1.AllowPaging = ;
GridView1.DataBind();
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);
string gridHTML = sw.ToString()。替换( \ '
。替换(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();
}

解决方案

看到这个

使用预览打印多页GridView - 1

打印多页GridView预览 - 2



ASP.NET GRIDVIEW控件中的打印功能


您好,



查看此链接



http://www.aspdotnet-suresh.com/2012/10/print-aspnet-gridview-data-using-c.html [ ^ ]


< asp:button id =Button1runat =serveronclick =Button1_Clickt ext =چاپصفحهجاریxmlns:asp =#unknown/> 



 protected void PrintAllPages(object sender,EventArgs e)
{
GridView1.AllowPaging = false;
GridView1.DataBind();
GridView1.HeaderRow.Cells [9] .Visible = false;
GridView1.FooterRow.Cells [9] .Visible = false;
//遍历行并隐藏第一列中的单元格
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());
GridV iew1.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;
//遍历行并隐藏第一列中的单元格
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();
}


i have gridview contol in my master page i have bind data in grid view using item templete ,
i have paging enabled on it when i click on print button it prints only current page i want to print all 10 pages at a time how to do this i have used this code to print but its not working can anyone help me .. thanks in advance


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


protected void  PrintAllPages(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();
}

解决方案

see this
Printing Multi Page GridView with Preview - 1
Printing Multi Page GridView with Preview - 2
and
PRINT FUNCTIONALITY IN ASP.NET GRIDVIEW CONTROL


Hi,

Check this Link

http://www.aspdotnet-suresh.com/2012/10/print-aspnet-gridview-data-using-c.html[^]


<asp:button id="Button1" runat="server" onclick="Button1_Click" text="چاپ صفحه جاری" xmlns:asp="#unknown" />


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();
        }


这篇关于在网格视图中打印所有页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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