Div Para Imprimir

Asked

Viewed 273 times

1

I am using a JS code that works very well to print:

function printdiv(divID) {
    var headstr = "<html><head><title></title></head><body>";
    var footstr = "</body>";
    var newstr = document.all.item(divID).innerHTML;
    var oldstr = document.body.innerHTML;
    document.body.innerHTML = headstr + newstr + footstr;
    window.print();
    document.body.innerHTML = oldstr;
    return false;
}    

I just need to print a few titles and there will be times I’ll have to print more than one grid. So I created in CSS the "print" and the "in print" and put everything inside the DIV divID.

What happens is that when the grid is populated with lots of data appearing scroll bar or paging it does not print all.

With the grid all populated, only if I put only the grid within this div, it prints out all the data.

I’ve tried a lot of different ways and all this trouble happens.

1 answer

1


I got it this way:

GridSuprimento.DataSource = gridCarregaSuprimento();
            GridSuprimento.AllowPaging = false;
            GridSuprimento.DataBind();
            GridRetirada.DataSource = gridCarregaRetirada();
            GridRetirada.AllowPaging = false;
            GridRetirada.DataBind();
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridSuprimento.RenderControl(hw);
            GridRetirada.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(lblTitulo.Text);
            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());

Browser other questions tagged

You are not signed in. Login or sign up in order to post.