Print Items Web Page

0

I would like to know how to print a web page, but I would not like to print the entire page, I would like it to print the title, and some grids, which are formatted (you would need to print all GridView data without paging ).

Unfortunately of all the ways I try, I did not print the grid without formatting. Paging is done in the same GridView control.

Does anyone know of any way I can print the grid with all the data?

    
asked by anonymous 11.05.2017 / 14:05

3 answers

0

I was able to solve the problem by setting it up like this:

sb.Append("<div ID='imprimir' align='Center' style='font-size:25px;'>Relatório de Planos</div>");
    
12.05.2017 / 19:34
1

I do not know about ASP, so maybe what I'm going to tell you here does not work very well.

In CSS we have the media queries, which are basically "modes" in which your page lies. Example:

@media screen and (max-width: 600px){
   body{
        width: 100%
   }
}

That is, when the device is screen and is at most 600px wide, it applies 100% width in the body.

With this we also have some options that deal with printing (% with%). Then you can use them as follows:

@media print{
    #my-grid{
        width: 1000px;
        height: 600px;
        top: 0;
        left: 0;
    }
}

That is, when you attempt to print from the browser, the print element will receive these new values and replace the old ones.

One way to test whether your style is being applied correctly is by using DevTool.

In chrome, open the console (f12), press ESC, and scroll to the #my-grid option. There you can select% with% (print) and check how your element stays when it will be printed.

    
12.05.2017 / 12:17
0

I was able to solve it by doing this:

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

The loaded Grid and the titles appear, but without configuration, I need to know how to configure the titles, I have not been able to resolve this part yet.

    
11.05.2017 / 22:29