Div To Print

1

I'm using a JS code that works great for printing:

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 some titles and there will be times when I have to print more than one grid . Then I created in the CSS the "print" and the "no print" and put everything inside the DIV divID .

What happens, is that when grid is populated with many data appearing scroll bar or pagination it does not print everything.

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

I have tried in many ways and they all have this problem.

    
asked by anonymous 24.04.2017 / 17:10

1 answer

1

I achieved 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());
    
17.05.2017 / 19:35